Version: 5.0
This method is used to execute the search and to look for matches of the search pattern string (or regular expression) and the target string. Each time a match is made, a Match object is created and added to a collection that is called a Matches collection. Syntax: object.
The Execute method is used with a RegExp object variable to look for a search string pattern (also known as a regular expression) inside a target string.
Each time a match is made (i.e., the search pattern is found inside the target string), a Match object is created and added to a Matches collection. Note that a match does not have to occur. Therefore the Execute method can return a Matches collection that is empty, or that contains one or more, objects.
<%
'this sub finds the matches
Sub RegExpTest(strMatchPattern, strPhrase)
'create variables
Dim objRegEx, Match, Matches, StrReturnStr
'create instance of RegExp object
Set objRegEx = New RegExp
'set the pattern
objRegEx.Pattern = strMatchPattern
'create the collection of matches
Set Matches = objRegEx.Execute(strPhrase)
'print out all matches
For Each Match in Matches
strReturnStr = "Match
found at position "
strReturnStr = strReturnStr
& Match.FirstIndex & ". Match Value is `"
strReturnStr = strReturnStr
& Match.value & "'."
'print
Response.Write(strReturnStr
& "<BR>")
Next
End Sub
'call the subroutine
RegExpTest "is.", "Is1 is2 Is3 is4"
%>Match found at position 4. Match Value is `is2'.