∟"RegExp" Class and Object for Regular Expression Support
This section describes the 'RegExp' class and objects used for pattern matches using regular expressions. oRegExp.execute(string) returns a MatchCollection collection object.
VBScript supports a built-in class called "RegExp" to provide regular expression support.
In order to perform a regular express task, you need to create a RegExp object with this syntax:
Set oRegExp = New RegExp
Note that we have to use the "Set" statement to assign an object to a variable.
Then we are ready to use properties and methods supported on the RegExp object, oRegExp:
oRegRex.Pattern - A String property containing the regular expression string to represent the search pattern.
oRegRex.Global - A Boolean property representing the global search flag. If turned on,
the search will be applied multiple times on the entire string.
oRegRex.IgnoreCase - A Boolean property representing the ignore-case search flag. If turned on,
the search will be applied case insensitively.
oRegRex.Test(string) - A method returning True, if a pattern match is found in the given string.
oRegRex.Execute(string) - A method returning a MatchCollection collection object
that contains a list of Match objects.
Each Match object represents a pattern match found in the given string.
oRegRex.Replace(string, replacement) - A method returning a copy of the given string
with each pattern match found and replaced with the replacement string.
The Match object has the following properties:
oMatch.Length - An integer property representing the number of characters of this pattern match.
oMatch.FirstIndex - An integer property representing the position where this pattern match was found in the string.
oMatch.Value - An String property representing this match found in the string.
The "Value" property is the default property.
So the "Value" property will be returned if a Match object is used in a String context.
oMatch.SubMatches - A SubMatches collection property that contains a list of Strings.
Each string represents a sub pattern match.
Notice that MatchCollection and SubMatches objects are collection objects.
They share same properties and methods as all collection objects. See the next section for details.