正则表达式 Regular Expressions

上一篇 / 下一篇  2012-09-19 15:36:47 / 个人分类:QTP

对大量的文本进行查找,对字符串进行比较,匹配,从而判断结果是否正确
在VBScript. 中,使用RegExp对象来支持正则表达式
RegExp 提供了3种属性和3种方法
Pattern, Global, IgnoreCase
Test,Replace, Execute

1.Pattern 匹配模式
+ 匹配前面的表达式1次or多次
. 匹配出换行符之外的任何单字符

eg.

Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
Set regEx = New RegExp 'create a ReExp
regEx.Pattern = patrn 'set pattern 
regEx.IgnoreCase = True ' Case ignore
regEx.Global = True 
Set Matches = regEx.Execute(Strng)
For Each Match in Matches
 RetStr= RetStr & "在" & Match.FirstIndex & "找到匹配项。匹配项为'" & Match.value & "'。" 

& vbCRLF
         Next
RegExpTest = RetStr
End Function

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



TAG: 正则表达式

 

评分:0

我来说两句

日历

« 2024-04-20  
 123456
78910111213
14151617181920
21222324252627
282930    

我的存档

数据统计

  • 访问量: 12062
  • 日志数: 13
  • 建立时间: 2012-09-11
  • 更新时间: 2012-09-26

RSS订阅

Open Toolbar