当前位置: 移动技术网 > IT编程>开发语言>正则 > asp match正则函数使用Matchs实例

asp match正则函数使用Matchs实例

2017年12月12日  | 移动技术网IT编程  | 我要评论


  说明   
  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   =   retstr   
  end   function   

  msgbox(regexptest("is.",   "is1   is2   is3   is4"))  

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网