cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expressions

SOLVED
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
Moderator

Re: Regular Expressions

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

extracts a 10-digit number from the variable MYCAPTION.


Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.
13 REPLIES 13
Community Hero

Re: Regular Expressions

Let's see an example of your caption string.

Contributor

Re: Regular Expressions

Motor - Ad 1112223445 name name
Contributor

Re: Regular Expressions

It's the number I require
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?

Contributor

Re: Regular Expressions

It could change position
Community Hero

Re: Regular Expressions

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

Contributor

Re: Regular Expressions

No just this 10 digit number
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.

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:
Watch the New Interview
APITestingMistake#2