Microsoft(R) Visual Basic(R) Scripting Edition 
FirstIndex 属性
 语言参考 
版本 5 

请参阅                  应用于


描述
返回在搜索字符串中匹配的位置。
语法
object.FirstIndex

object 参数总是一个 Match 对象。

说明
FirstIndex 属性使用从零起算的偏移量,该偏移量是相对于搜索字符串的起始位置而言的。换言之,字符串中的第一个字符被标识为字符 0。 下面的例子说明了 FirstIndex 属性的用法:
~Function RegExpTest(patrn, strng)
  Dim regEx, Match, Matches		' 建立变量。
  Set regEx = New RegExp			' 建立正则表达式。
  regEx.Pattern = patrn			' 设置模式。
  regEx.IgnoreCase = True			' 设置是否区分大小写。
  regEx.Global = True			' 设置全局可用性。
  Set Matches = regEx.Execute(strng)	' 执行搜索。
  For Each Match in Matches		' 遍历 Matches 集合。
    RetStr = RetStr & "匹配 " & I & " 位于 "
    RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
    RetStr = RetStr & Match.Value & "'." & vbCRLF
  Next
  RegExpTest = RetStr
End Function

MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))