On Fri, 13 Jul 2007 22:40:20 -0400, "Bernie Deitrick" <deitbe @ consumer dot
org wrote:
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
Bernie,
Excerpted From:
http://support.microsoft.com/default...02&Product=vbb
• Global: Sets a Boolean value or returns a Boolean value that indicates
whether a pattern must match all the occurrences in a whole search string, or
whether a pattern must match just the first occurrence.
In my response to the OP, I was just modifying his routine. But, ordinarily I
set the Global property to True, so as to enable multiple matches.
Here's the routine modified, with the changes noted:
==========================================
Option Explicit
Sub x()
Dim regEx As Object
Dim Matches As Object
'-------------------
Dim i As Long
'--------------------
Dim s As String
s = "First Name: Joe First Name: Bernie"
Set regEx = CreateObject("VBScript.RegExp")
'-----------------------
regEx.Global = True
'-----------------------
regEx.Pattern = "First Name: (\w+)"
Set Matches = regEx.Execute(s)
'------------------------------
For i = 0 To Matches.Count - 1
Debug.Print Matches(i).submatches(0)
Next i
'--------------------------------
End Sub
==============================================
--ron