Sub MethExecute()
Dim objRegEx, objMatch, strString, strDisplayMsg
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "bear"
objRegEx.Global = True
objRegEx.IgnoreCase = True
strString = "Once upon a time there were three little Bears. There was mama Bear, papa Bear and baby bear"
strDisplayMsg = ""
For Each objMatch in objRegEx.Execute(strString)
strDisplayMsg = strDisplayMsg & " An instance of " + objMatch.Value & " found at position " & CStr(CInt(objMatch.FirstIndex) + 1) & VbCrlf
Next
MsgBox(strDisplayMsg)
End Sub
|