cancel
Showing results for 
Search instead for 
Did you mean: 

Regular expression

SOLVED
Highlighted
Contributor

Regular expression

I am trying to do a check on a user input. I would like to check to see if a user enters a valid ip number. I would like to do something like:  BuiltIn.StrMatches(ip, "10.10." + [0-9]+ + "." +[0-9]+). Where ip in the value of the user's IP address and I would like to try to String match is with the regular expression "10.10." + [0-9]+ + "." +[0-9]+, or something along those lines. I want to verify that the first number is 10 then a period then 10 again then a three digit number or less then a period then another three digit number or less. 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Regular expression

Other way around... if "ip" represents what the user entered, that needs to be the SECOND parameter for StrMatches 

 

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

 

You have the right general idea.  Take a look at that article, get your parameters in the right place and make sure you're using proper regular expression syntax.


Robert Martin
[Community Expert Group]
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
Extensions available

View solution in original post

4 REPLIES 4
Community Hero

Re: Regular expression

Other way around... if "ip" represents what the user entered, that needs to be the SECOND parameter for StrMatches 

 

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

 

You have the right general idea.  Take a look at that article, get your parameters in the right place and make sure you're using proper regular expression syntax.


Robert Martin
[Community Expert Group]
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
Extensions available

View solution in original post

Community Hero

Re: Regular expression

Here's the reference for regular expressions in TestComplete:

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

 

 

What code have you tried and what happens when you run it?

Contributor

Re: Regular expression

I have tried BuiltIn.StrMatches(ip, "10.10." + [0-9]+ + "." +[0-9]+) and testcomplete does not like that. 

Community Hero

Re: Regular expression

Right... because, as mentioned above, you have your parameters backwards.  The expression should be the FIRST parameter, the string you're testing should be the second parameter.  Reverse your parameters, check your syntax for your expression, and try again.


Robert Martin
[Community Expert Group]
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
Extensions available
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors