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

user692942
  • 16,398
  • 7
  • 76
  • 175
user3803807
  • 285
  • 4
  • 18
  • ` [0-9\s]+` does this work for you..check here http://regexr.com/3cnbu – rock321987 Feb 03 '16 at 05: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 – user3803807 Feb 03 '16 at 05:19
  • i don't know vbscript. You have to use something like `replace` to replace the spaces with no spaces – rock321987 Feb 03 '16 at 05:27

2 Answers2

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"
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
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

Community
  • 1
  • 1
rock321987
  • 10,942
  • 1
  • 30
  • 43