OBJECT: Matches Collection
Implemented in version 5.0
is a collection of objects that contains the results of a search and match operation that uses a regular expression.
Simply put, a regular expression is a string pattern that you can compare against all or a portion of another string. However, in all fairness, be warned that regular expressions can get very complicated.
object can be used to search for and match string patterns in another string. A
object is created each time the
object finds a match. Since, zero or more matches could be made, the
object actually return a collection of
objects which is refered to as a
The following code is a simplier, working version of a program published by Microsoft. Note how the
For Each ... Next
statement is used to loop through the
'this sub finds the matches
Sub RegExpTest(strMatchPattern, strPhrase)
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
'call the subroutine
RegExpTest "is.", "Is1 is2 Is3 is4"
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'.
Returns an integer that tells us how many
objects there are in the
property allows us to retreive the value of an item in the collection designated by the specified
argument and also to set that value by using
[ = itemvalue]