【转】正则表达式01
1.如何使用正则表达式
首先生成正则表达式对象
Set regEx = New RegExp
然后设置正则表达式对象的属性
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
最后使用正则表达式的方法来实现需求
regEx.Replace(string1, string2)
regEx.Test(string)
regEx.Execute(string)
2.正则表达式对象的属性与方法:
属性:
Global Property
IgnoreCase Property
Pattern Property
方法:
Execute
Preplace
Test
'定义变量及初始化 Dim a,b,c a="mooooon" b="mo1n" '正则表达式以及执行搜索 Set myReg= New RegExp '生成正则表达式对象 myReg.Pattern =b '设置正则表达式公式(必须有本语句) myReg.IgnoreCase = True '表示匹配时忽略大小写(非必须语句) myReg.Global = True '非必须语句 c=myReg.test(a) '执行搜索,如果在a中搜到a,则返回true,否则faulse。 '报告执行结果 If c Then Reporter.ReportEvent 2, "测试结果", "a中包括b" else Reporter.ReportEvent 1, "测试结果", "a中不包括 b" End If
-----------------------------------------------------------------------------------------------------------