Description
The Match object can only be created through the Execute method of the RegExp object. This method actually returns a set of Match objects. All the matching object attributes are read-only.
When executing a regular expression, zero or multiple Match objects may be generated. Each Match object provides the access to strings found by regular expressions, the length of strings, and the location of matching indexes.
The following code illustrates the usage of the Match object:
Function RegExpTest (patrn, strng)
Dim regEx, Match, Matches 'to create a variable.
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 Global replacement.
Set Matches = regEx. Execute (strng) 'to Execute the search.
For Each Match in Matches 'traverses the Matches set.
RetStr = RetStr & "Match" & I & "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 "))