最新消息:前端博客、web前端博客、Angularjs、javascript、jQuery、HTML5、CSS3

ASP中一些正则表达使用

ASP AZ 1663浏览 0评论

前几天帮朋友弄正则,可惜自己这方面也不强,所以记下这些Function。给有需要的人一些提示,也加强下自己的技能

'找到一个table内容
Function getTABLE(strHTML)
Dim tableRegExp, Match, Matches
Set tableRegExp = New RegExp
tableRegExp.IgnoreCase = True
tableRegExp.Global = True
tableRegExp.Pattern = "(<table)+[^<>]*>([\s\S]*?)</table>"
Set Matches = tableRegExp.Execute(strHTML)
For Each Match in Matches
strHtml = Match.Value
Next
getTABLE = strHTML
Set tableRegExp = Nothing
End Function

'删除链接只留内容
Function delA(strHTML)
Set aRegExp = New RegExp
aRegExp.IgnoreCase = True
aRegExp.Global = True
aRegExp.Pattern = "<a[^>]+>(.+?)<\/a>"
delA = aRegExp.replace(strHTML,"$1")
Set aRegExp = Nothing
END Function

'删除html标签
Function delHtml(strHtml)
Dim html, strOutput
Set html = New RegExp ' 建立正则表达式
html.IgnoreCase = True ' 设置是否区分大小写
html.Global = True '是匹配所有字符串还是只是第一个
html.Pattern = "(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)" ' 设置模式引号中的是正则表达式,用来找出html标签
strOutput = html.Replace(strHtml, "") '将html标签去掉
strOutput = Replace(strOutput, "<", "<") '防止非html标签不显示
strOutput = Replace(strOutput, ">", ">")
delHtml = strOutput
Set html = Nothing
End Function

转载请注明:TUTERM.COM » ASP中一些正则表达使用

如果您觉得本文的内容对您的学习有所帮助,您可以支付宝(左)或微信(右):
alipay weichat

您必须 登录 才能发表评论!