当前位置: 移动技术网 > IT编程>开发语言>正则 > VBS中的正则表达式的用法大全 原创

VBS中的正则表达式的用法大全 原创

2018年05月29日  | 移动技术网IT编程  | 我要评论
VBS正则表达式函数 主要用在asp中效果明显 1、表单验证功能 代码如下:Function RegExpTest(patrn, strng) &nbs
VBS正则表达式函数
主要用在asp中效果明显 
1、表单验证功能
代码如下:

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.FirstIndex & "。匹配的长度为"&" "
RetStr = RetStr & Match.Length &" "
      RetStr = RetStr & Matches(0) &" "      '值为123
     RetStr = RetStr & Matches(1)&" "      '值为44
    RetStr = RetStr & Match.value&" "    '值为123和44的数组
     RetStr = RetStr & vbCRLF
   Next
   RegExpTest = RetStr
End Function
MsgBox(RegExpTest("\d+", "123a44"))

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网