Matches set
A set of regular expressions that match objects.
Description
The matches set contains several independent match objects, which can only be created using the execute method of the Regexp object. Similar to an independent match object attribute, one attribute of the matches set is read-only.
When executing a regular expression, zero or multiple match objects may be generated. Each match object provides the access entry of the string that matches the regular expression, the length of the string, and the index that identifies the matching position.
The following code describes how to use a regular expression to search for a matches set and how to traverse the set cyclically:
Function regexptest (patrn, strng)
Dim RegEx, match, matches 'to create variables.
Set RegEx = new Regexp 'to create a regular expression.
RegEx. pattern = patrn 'setting mode.
RegEx. ignorecase = true' is used to set Case sensitivity.
RegEx. Global = true' sets full match.
Set matches = RegEx. Execute (strng) 'to execute the search.
For each match in matches 'cyclically traverses the matches set.
Retstr = retstr & "match found at position"
Retstr = retstr & Match. firstindex & ". Match value is '"
Retstr = retstr & Match. Value & "'." & vbcrlf
Next
Regexptest = retstr
End Function
Msgbox (regexptest ("is.", "is1 is2 is3 is4 "))