user3803807
user3803807

Reputation: 315

To extract text from string

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

Upvotes: 1

Views: 79

Answers (2)

rock321987
rock321987

Reputation: 11032

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

Upvotes: 0

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

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"

Upvotes: 2

Related Questions