Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

Length Property

Updated: March 2009

Returns the length of a match found in a search string.


The object argument is always a Match object.

The following code illustrates the use of the Length property:

Function RegExpTest(patrn, strng)
    Dim regEx, Match, Matches, s

    ' Create the regular expression.
    Set regEx = New RegExp
    regEx.Pattern = patrn
    regEx.IgnoreCase = True
    regEx.Global = True

    ' Do the search.
    Set Matches = regEx.Execute(strng)

    ' Iterate through the Matches collection.
    s = ""
    For Each Match in Matches
      s = s & "Match found at position "
      s = s & Match.FirstIndex & ".  "
      s = s & "Match Length is "
      s = s & Match.Length & "."
      s = s & vbCRLF

    RegExpTest = s
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))




March 2009

Reformatted code example.

Information enhancement.

Community Additions

© 2015 Microsoft