我的博客| Blog
- ·微信小程序错误:VM564:...
- ·mongodb3.2设置密码...
- ·单行滚动代码-单行滚动效果
- ·自己动手制作图形字体,以便于...
- ·MySQL无限级分类PHP按...
- ·Windows下的Apach...
- ·如何将网站上的文章分享到微信...
- ·PHP实现自动获取本月第几个...
联系我| Contact Me
- 电话:18681257080
- QQ:271538869
- 邮编:518020
- 信箱:service@08321.org
- 地址:四川省内江市资中县
诚信稳健,和谐共赢
- 以诚信为立世之本,在稳健的基础上,不断寻求创新与突破。
- 以务实严谨、精微细致的专业精神,为客户做最优质的策划,实现效果最大化。
成功,依稀可见
- 成功,依稀可见!——依希设计
- 成功是很多方面的,很多小的成功可以积累成大的成功,而真正意义上的成功是永远不可能到达的,所以只能依稀可见。
我的博客
ASP正则对象简单使用说明
来源:本站编辑 发布日期:2009-8-27 已有 人浏览过此信息
这篇文章是把asp中使用正则的一些常用的东西做了一个总结。当然,这些还是很重要的,熟悉之前可能需要先记住这些东西。
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(0).SubMatches.Item(0) ‘取得第一个匹配,表达式中()的内容
注意: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)取得值的
相关应用:
正则表达式提取图片路径
<%
set rs=conn.execute("select * from news where id=26")
content=rs("content")
rs.close:set rs=nothing
response.write(content)
response.write("正则表达式提取图片路径:<br/>")
set regex=new RegExp
regex.pattern="<img.*src=([^\']*) \/>"
regex.IgnoreCase=True
regex.Global=True
set matches=regex.execute(content)
response.write(matches(0).submatches.item(0))
'dim mat
'for each mat in matches
'response.write(mat.submatches.item(0))
'next
%>
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(0).SubMatches.Item(0) ‘取得第一个匹配,表达式中()的内容
注意: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)取得值的
相关应用:
正则表达式提取图片路径
<%
set rs=conn.execute("select * from news where id=26")
content=rs("content")
rs.close:set rs=nothing
response.write(content)
response.write("正则表达式提取图片路径:<br/>")
set regex=new RegExp
regex.pattern="<img.*src=([^\']*) \/>"
regex.IgnoreCase=True
regex.Global=True
set matches=regex.execute(content)
response.write(matches(0).submatches.item(0))
'dim mat
'for each mat in matches
'response.write(mat.submatches.item(0))
'next
%>