Matches set
Regular ExpressionMatchObject set.
Description
MatchesSet contains several independentMatchObject, which can only be usedRegExpObjectExecuteMethod. IndependentMatchObject Attributes are the same,Matches'An attribute of the set is read-only.
When executing a regular expression, zero or multipleMatchObject. EachMatchThe 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 obtainMatchesSet and how to traverse the set cyclically:
Function RegExpTest(patrn, strng) Dim regEx, Match, Matches ' Create a variable. Set regEx = New RegExp ' Create a regular expression. regEx.Pattern = patrn ' Set the mode. regEx.IgnoreCase = True ' Set whether to be case sensitive. regEx.Global = True ' Set full match. Set Matches = regEx.Execute(strng) ' Execute the search. For Each Match in Matches ' Loop TraversalMatchesSet. RetStr = RetStr & "Match found at position " RetStr = RetStr & Match.FirstIndex & ". Match Value is '" RetStr = RetStr & Match.Value & "'." & vbCRLF Next RegExpTest = RetStrEnd FunctionMsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))