用户登录
用户注册

分享至

VBS教程:对象-Match 对象

  • 作者: 达?矢抾哆拉?
  • 来源: 51数据库
  • 2021-09-01

match 对象

提供了对正则表达式匹配的只读属性的访问。

说明

match 对象只能通过 regexp 对象的 execute 方法来创建,该方法实际上返回了 match 对象的集合。所有的 match 对象属性都是只读的。

在执行正则表达式时,可能产生零个或多个 match 对象。每个 match 对象提供了被正则表达式搜索找到的字符串的访问、字符串的长度,以及找到匹配的索引位置等。

下面的代码说明了 match 对象的用法:

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 & "match " & i & " found at position "    retstr = retstr & match.firstindex & ". match value is "'    retstr = retstr & match.value & "'." & vbcrlf  next  regexptest = retstrend functionmsgbox(regexptest("is.", "is1 is2 is3 is4"))
软件
前端设计
程序设计
Java相关