FirstIndex attributes
Returns the matched position in the search string.
object.FirstIndex
ObjectThe parameter is alwaysMatchObject.
Description
FirstIndexThis attribute uses the offset calculated from zero. This offset is relative to the start position of the search string. In other words, the first character in the string is identified as 0. The example below illustratesFirstIndexAttribute usage:
~Function RegExpTest(patrn, strng) Dim regEx, Match, Matches
'
Create a variable. Set regEx = New RegExp
'
Create a regular expression. regEx.Pattern = patrn
'
Set the mode. regEx.IgnoreCase = True
'
Set whether to be case sensitive. regEx.Global = True
'
Set global availability. Set Matches = regEx.Execute(strng)
'
Execute the search. For Each Match in Matches
'
Traversal Matches
Set. RetStr = RetStr & "
Match " & I & "
Located in "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))