Ask a Question

Using RegExp with aqString.Contains

SOLVED
TruthVoyager
New Contributor

Using RegExp with aqString.Contains

I am trying to check to see if a string contains any letters using the following code. 

 

          if(aqString.Contains(info[i], /[A-Za-z]/) != -1)
          {
            an = "a";
          }

This if returns false even when it should return true. Any idea what is wrong? 

 

Thank you, 

4 REPLIES 4
Marsha_R
Champion Level 3

According to this

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/methods.html

 

"contains" is obsolete

 

"find" is the replacement

 

See if that works for you.

 

ETA:  This looks like a better option

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/strmatches.html

 

and here is TC information on regular expressions

https://support.smartbear.com/testcomplete/docs/reference/misc/regular-expressions.html

tristaanogre
Esteemed Contributor

Also, both "contains" and "find" don't support regular expressions.  The second parameter is the literal "sub-string" that you're searching for, not a regular expression.  This is why you're getting a false every time.  If you want to determine if a string contains another string based upon regular expression, you should use aqString.StrMatches (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/strmatches.html)


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

^^ Great minds think alike @tristaanogre   Man Tongue

Thank you very much!

 

 

 

cancel
Showing results for 
Search instead for 
Did you mean: