asp 正则表达式的中分组的问题

coolria 2010-10-08 02:12:30
比如 str="<div>123</div><li>456</li><li>789</li>";
正则表达式应该怎么写才能得到123456789这个字符串,我所知道的在JAVA中可以用分组:
<div>[\d]+</div><li>([\d]+)</li>><li>([\d]+)</li>

这样的话group(0)=123 group(1)=456 group(2)=789

那么在asp里应该如何写呢?
...全文
74 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2010-10-08
  • 打赏
  • 举报
回复

<%
str= "<div>123</div><li>456</li><li>789</li>"
Set re = New RegExp
With re
.Global = True
.IgnoreCase = True
.Pattern = "<([^>]+)>(\d+)<\/\1>"
Set col = .Execute(str)
For Each m In col
Response.Write m.SubMatches(1) & "<br>"
Next
End With
Set re = Nothing
%>
shenzhenNBA 2010-10-08
  • 打赏
  • 举报
回复
看看这个高效率的函数 FunRemoveHTML(refString)


dim str,rx
str="<a href='http://www.code-design.cn' target='_blank'>去除HTML标签的功能函数ABCDEFGHIJK</a><div>123</div><li>456</li><li>789</li>"

Function FunRemoveHTML(refString)
dim regEx,temp
set regEx=new RegExp
regEx.IgnoreCase=true
regEx.Global = true
regEx.pattern="<[^>]+>|</[^>]+"
temp=regEx.replace(refString,"")
set regEx=nothing
funRemoveHTML=temp
temp=null
End function

response.Write "<br>str = " & server.HTMLEncode(str)
response.Write "<br>str2 = " & FunRemoveHTML(str)
blacklong 2010-10-08
  • 打赏
  • 举报
回复
一样的。

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧