1

I need to match to retrieve the number from text like below

Some Text. Your claim number is 123 456 789. Some more Text

I have tried various ways similar to below with no luck

MyReg.pattern = "Your claim number is [(/d+\s+)]+[.]$"

Any ideas on how I can retrieve the numbers from the string below would be appreciated. Preference would be to retrieve 123456789. If not possible 123 456 789 would be OK as I can remove the white spaces after

3
  • ` [0-9\s]+` does this work for you..check here regexr.com/3cnbu Commented Feb 3, 2016 at 5:07
  • Thanks. It brings back Your claim number is 123 456 789. Is there anyway to just bring back the numbers. Alternatively since it will always be in the format 123 456 789 can I create the expression using the 3 numbers with the space inbetween Commented Feb 3, 2016 at 5:19
  • i don't know vbscript. You have to use something like replace to replace the spaces with no spaces Commented Feb 3, 2016 at 5:27

2 Answers 2

2

Your [(/d+\s+)]+[.]$ fails because of the $ (no EOS immediately after the dot), the /d instead of \d and the ()+ which are not part of the character class.

You'd get the digits by deleting the non-digits:

>> s = "Some Text. Your claim number is 123 456 789. Some more Text"
>> Set r = New RegExp
>> r.Pattern = "[^\d]+"
>> r.Global = True
>> WScript.Echo qq(r.Replace(s, ""))
>>
"123456789"
Sign up to request clarification or add additional context in comments.

Comments

0

Try this [0-9\s]+.

It seems it is not possible to skip some character and then find a match as the search is consecutive as mentioned here. Alternatively you can use replace for replacing the space

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.