12-02-2010, 01:32 PM
Code:
Dim regEx: Set regEx = New RegExp
regEx.Pattern = "(?:código )(\d+)"
MsgBox regEx.Execute("this is código 86 testing numeric").Item(0).SubMatches.Item(0)
(?: ) is a non-capturing group, so you are assured the digits will end up in the first SubMatch of the SubMatches collection. If you want to break the code down a little further:
Code:
Dim txtstrng: txtstrng = "this is código 86 testing numeric"
Dim regEx: Set regEx = New RegExp
regEx.Pattern = "(?:código )(\d+)"
Dim regExMatches: Set regExMatches = regEx.Execute(txtstrng)
For i = 0 To regExMatches.Count-1
MsgBox "código match number " & i & ": " & regExMatches.Item(i).SubMatches.Item(0)
Next
This will iterate through each match if there are more than one.