VBScript » RegExp » Execute

Version: 5.0

Syntax:
object.Execute (TargetString)
TargetString
There is one mandatory argument, the target string to be searched. The search string pattern (regular expression) is declared using the Pattern property.

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.

Examples

Code:
<%
'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"
%>
Output:
Match found at position 4. Match Value is `is2'.