View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Richard L Rosenheim Richard L Rosenheim is offline
external usenet poster
 
Posts: 2
Default Problem with RegEx and matches

I'm trying to extract a numeric substring from a string. Here's the code
that I have:

Const patternNetTerms = "^.*?(\d+).*?$"
Dim regEx
Dim matches
Dim match

Set regEx = New RegExp
'Set regEx = CreateObject("vbscript.regexp")
regEx.Pattern = patternNetTerms
regEx.IgnoreCase = False
regEx.Global = True
regEx.MultiLine = False
Set matches = regEx.Execute(sNetTerms)

If matches.Count = 1 Then
MsgBox "# of matches: " & matches.Count
For Each match In matches
MsgBox "Match: " & match.value
Next
End If

When the string is "Net 10 Days", the only output I'm getting is the entire
string. How do I retrieve the "10"? According to the regex calculator at
http://www.codehouse.com/webmaster_tools/regex/, my expression does works.
So, my problem appears to be in how I'm trying to retrieve the matches.

Anyone have any suggestions as to what I'm doing wrong?

TIA,

Richard