OBJECT: RegExp
RegExp
VBScript 5.0
The RegExp object is used to search for and match string patterns in another string.
A Match object is created each time the RegExp object finds a match.
Since, zero or more matches could be made,
the RegEXp object actually return a collection of Match objects which is
refered to as a Matches collection.
The following code is a simplier, working version of a program published by Microsoft.
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
'find all matches
objRegEx.Global = True
'set case insensitive
objRegEx.IgnoreCase = True
'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 & "'." & "<BR>" & vbCrLf
'print
Response.Write(strReturnStr)
 : Next
End Sub
'call the subroutine
RegExpTest "is.", "Is1 is2 Is3 is4"
%>
Output:
Match found at position 0. Match Value is 'Is1'.
Match found at position 4. Match Value is 'is2'.
Match found at position 8. Match Value is 'Is3'.
Match found at position 12. Match Value is 'is4'.
PROPERTIES
Global Property
This property is only used with a RegExp object variable and returns a Boolean value.
False signifies that a search should only find the first occurrence of a match.
True signifies that a search should find all occurrences of a match.
Syntax: object.FirstIndex = [ True | False ]
IgnoreCase Property
This property is only used with a RegExp object variable and returns a Boolean value.
False signifies that a search should be case-sensitive (i.e., upper versus lower case).
True signifies that a search should ignore case in a match.
Syntax: object.IgnoreCase = [ True | False ]
Pattern Property
This property is the regular expression pattern (string) that is to be matched during the search.
It is only used with a RegExp object variable.
Syntax: object.Value = [ SearchPatternString ]
METHODS
Execute Method
This method is used to execute the search.
Syntax: object.Execute
Replace Method
This method is used to replace text found in a regular expression search.
Do not confuse this method with the Replace function.
Syntax: RegExp.Replace
(String1, String2)
Test Method
This method is used to determine if the search pattern occurs within a specified string.
True is returned if the pattern is found.
Otherwise, False is returned.
Syntax: RegExp.Execute