regular expression parse string Perl $1 VBScript.RegExp
How would you use it to find multiple matches: if
s = "First Name: Joe, First Name: Ron"
Hi Bernie. Try setting the Global search to True.
Sub x()
Dim regEx As Object
Dim Matches As Object
Dim s As String
s = "First Name: Joe, First Name: Ron"
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "First Name: (\w+)"
regEx.Global = True
regEx.IgnoreCase = True
Set Matches = regEx.Execute(s)
Debug.Print Matches(0).Submatches(0)
Debug.Print Matches(1).Submatches(0)
'or
Dim sName
For Each sName In Matches
Debug.Print sName.Submatches(0)
Next sName
End Sub
--
Dana DeLouis
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Ron,
How would you use it to find multiple matches: if
s = "First Name: Joe, First Name: Ron"
your debug.print returns Joe - how do you get to Ron as well?
TIA,
Bernie
"Ron Rosenfeld" wrote in message
...
On Fri, 13 Jul 2007 17:50:34 -0700, "
wrote:
I want to use a VBScript regular expression to parse a string in VBA.
Can some kind soul get this to work?
Thanks.
Sub x()
Dim s As String
s = "First Name: Joe"
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "First Name: (\w+)"
Set Matches = regEx.Execute(s)
' This statement fails - no such property
Set oMatch = Matches.subMatches(0)
' I can enumerate through Matches but the enumeration doesn't include
"Joe"
End Sub
Sub x()
Dim regEx As Object
Dim Matches As Object
Dim s As String
s = "First Name: Joe"
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "First Name: (\w+)"
Set Matches = regEx.Execute(s)
' This statement fails - no such property
' Set oMatch = Matches.subMatches(0)
Debug.Print Matches(0).submatches(0)
End Sub
--ron
|