cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expressions

SOLVED
Highlighted
Contributor

Regular Expressions

Hello,

I have a header bar with a caption property that contains words and numbers. I want to extract the a 10 digit number from the caption string.

I've read through the documentation however I still don't understand how to implement this. The examples also don't seem to help my understanding of the syntax.

I've saved the caption property into a variable. Then created a new instance of the RegExp and tried to match method to return the numbers. I've tried loads of variations but can't seem to get it to work.

re = HIUtils.RegExpr ([0-9]);

re.Match (MYCAPTION);

Log.Message (MYCAPTION);

This is the latest I've tried however I've tried RegExp new instance and I'm just not getting the way to set it up.






1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Regular Expressions

MYCAPTION.match(/\d{10}/)[0]

extracts a 10-digit number from the variable MYCAPTION.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

13 REPLIES 13
Highlighted
Community Hero

Re: Regular Expressions

Let's see an example of your caption string.

Highlighted
Contributor

Re: Regular Expressions

Motor - Ad 1112223445 name name
Highlighted
Contributor

Re: Regular Expressions

It's the number I require
Highlighted
Community Hero

Re: Regular Expressions

Is the number always in the same position in the string or is the "Motor - Ad" part a random size?

Highlighted
Contributor

Re: Regular Expressions

It could change position
Highlighted
Community Hero

Re: Regular Expressions

Will there be any other numbers before the 10 digit one?

Highlighted
Contributor

Re: Regular Expressions

No just this 10 digit number
Highlighted
Community Hero

Re: Regular Expressions

What I did for something similar was to use aqString.Trim to get all the spaces out of the string and then loop through it a character at a time looking for a digit.  That will get you the position of the first digit.  Then you can use aqString.Substring to get the 10 digits.

 

I never found a way to use the regular expressions for this.  Looks like you can use them to compare but not for string manipulation.

Highlighted
Contributor

Re: Regular Expressions

I'll give that a try in the morning...Thanks very much for your help Marsha.
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare images using the Region Checkpoint

See replies!

Converting UTC TimeDate in an Excel file

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors