Implemented in version 5.0
object is used to access the three read-only properties associated with 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.
'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'.
This property returns the position, counted from the left with the first position being numbered zero, in a string where a match was made.
This property returns the length of the matched text found in a search string.
This property returns the actual text that was matched during the search.