Sub
Macro1()
'
' Macro1 Macro
' Macro recorded 2007-6-19 by JK Zhang
'
'
MsgBox (TestRegExp( " is. " , " IS1 is2 IS3 is4 " ))
End Sub
Function TestRegExp(myPattern As String , myString As String )
' Create objects.
Dim objRegExp As Object
Dim objMatch As Object
Dim colMatches As Object
Dim RetStr As String
' Create a regular expression object.
Set objRegExp = CreateObject ( " vbscript.regexp " )
' Set the pattern by using the Pattern property.
objRegExp.Pattern = myPattern
' Set Case Insensitivity.
objRegExp.IgnoreCase = True
' Set global applicability.
objRegExp.Global = True
' Test whether the String can be compared.
If (objRegExp.Test(myString) = True ) Then
' Get the matches.
Set colMatches = objRegExp.Execute(myString) ' Execute search.
For Each objMatch In colMatches ' Iterate Matches collection.
RetStr = RetStr & " Match found at position "
RetStr = RetStr & objMatch.FirstIndex & " . Match Value is ' "
RetStr = RetStr & objMatch.Value & " '. " & vbCrLf
Next
Else
RetStr = " String Matching Failed "
End If
TestRegExp = RetStr
End Function
'
' Macro1 Macro
' Macro recorded 2007-6-19 by JK Zhang
'
'
MsgBox (TestRegExp( " is. " , " IS1 is2 IS3 is4 " ))
End Sub
Function TestRegExp(myPattern As String , myString As String )
' Create objects.
Dim objRegExp As Object
Dim objMatch As Object
Dim colMatches As Object
Dim RetStr As String
' Create a regular expression object.
Set objRegExp = CreateObject ( " vbscript.regexp " )
' Set the pattern by using the Pattern property.
objRegExp.Pattern = myPattern
' Set Case Insensitivity.
objRegExp.IgnoreCase = True
' Set global applicability.
objRegExp.Global = True
' Test whether the String can be compared.
If (objRegExp.Test(myString) = True ) Then
' Get the matches.
Set colMatches = objRegExp.Execute(myString) ' Execute search.
For Each objMatch In colMatches ' Iterate Matches collection.
RetStr = RetStr & " Match found at position "
RetStr = RetStr & objMatch.FirstIndex & " . Match Value is ' "
RetStr = RetStr & objMatch.Value & " '. " & vbCrLf
Next
Else
RetStr = " String Matching Failed "
End If
TestRegExp = RetStr
End Function