FirstIndex Property
Returns the location of the match in the search string.
object.FirstIndex
The Object argument is always a Match object.
Description
The FirstIndex property uses an offset from zero, which is relative to the starting position of the search string. In other words, the first character in the string is identified as character 0. The following example illustrates the use of the FirstIndex property:
~Function RegExpTest(patrn, strng) Dim regEx, Match, Matches' Create a variable. Set regEx = New RegExp' Establishes a regular expression. regEx.Pattern = patrn' Set the mode. regEx.IgnoreCase = True ' Sets whether the case is case-sensitive. regEx.Global = True' Set global availability. Set Matches = regEx.Execute(strng)' Perform a search. For Each Match in Matches' Traverse Matches Collection. RetStr = RetStr & "The " & I & " In " RetStr = RetStr & Match.FirstIndex & ". Match Value is "' RetStr = RetStr & Match.Value & "'." & vbCRLF Next RegExpTest = RetStrEnd FunctionMsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))