ASP正则对象总结

来源:互联网 发布:詹姆斯库克大学 知乎 编辑:程序博客网 时间:2024/05/16 06:18

1.建立正则对象
Set regEx=New RegExp ‘建立正则对象
属性:
regEx.Pattern=vpattern ‘获取正则表达式
regEx.IgnoreCase=True ‘是否区分大小写匹配
regEx.Global=True ‘是否进行全局匹配
方法:
Set Matches=regEx.Execute(str) ‘对str进行搜索,返回匹配到的Matches集合   
regEx.Replace(str1,str2) ‘用str2替换 str1中匹配到的字符串
regEx.Test(str) ‘测试str中是否有符合匹配,有则返回True

2.集合对象(Matches)的使用
Set Matches=regEx.Execute(str) ‘对str进行搜索,返回匹配到的Matches集合
属性:
Matches.Count ‘匹配到的个数
Matches.Item(i) ‘第i个匹配到的字符串
注意:Matches.Item(i)=Matches(0).Value=Matches(I)
方法: 无
3.单个集合对象(Match)的使用
‘ 其实就是Matches集合中的单个匹配到的对象,通过For Each……Next得到
For Each Match In Matches
    Match.FirstIndex ‘属性,返回在搜索字符串中匹配的位置
    Match.Length ‘属性,匹配的字符串的长度
    Match.Value ‘属性,返回在一个搜索字符串中找到的匹配的值或文本
Next
‘Match中还存在一个SubMatches集合
Match.SubMatches.Count ‘ 属性,匹配个数
Match.SubMatches.Item(I) ‘属性,某个匹配

其实,集合都可以用M(i)或M(i).value或M.Item(i)取得值的
 

原创粉丝点击