Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

FirstIndex Property

 

Returns the position in a search string where a match occurs.

object.FirstIndex

The object argument is always a Match object.

The FirstIndex property uses a zero-based offset from the beginning of the search string. In other words, the first character in the string is identified as character zero (0). The following code illustrates the use of the FirstIndex 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 Value is '"
    s = s & Match.Value & "'."
    s = s & vbCRLF
  Next

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

Requirements

Change History

Date

History

Reason

March 2009

Reformatted code in example.

Information enhancement.

Show:
© 2015 Microsoft