今天在改一套b2b的电子商务系统时,发现ASP正则,虽然用ASP很久了,但从来没用过正则表达式,这套系统中有个正则的函数很不错,自己看吧。
复制代码 代码如下:
<% Function RegExpTest(patrn, strng) Dim regEx, Match, Matches ' 建立变量。 Set regEx = New RegExp ' 建立正则表达式。 regEx.Pattern = patrn ' 设置模式。 regEx.IgnoreCase = False ' 设置是否区分字符大小写。 regEx.Global = True ' 设置全局可用性。 Set Matches = regEx.Execute(strng) ' 执行搜索。 For Each Match In Matches ' 遍历匹配集合。 On Error Resume Next RetStr = RetStr & Match.Value&"|" Next RegExpTest = RetStr End Function str = "我来自#5565#哈哈" strInfo = RegExpTest("#\w+(\((\b[,0-9]+\b)?\))?#", str) Response.Write(strInfo) %>
再看一例:复制代码 代码如下:
Function noHtml(str) Dim re Set re=New RegExp re.IgnoreCase =True re.Global=True re.Pattern="(\<.*?\>)" str=re.Replace(str,"") re.Pattern="(\<\/.*?\>)" str=re.Replace(str,"") noHtml=str End Function
查看更多关于中的正则表达式运用代码_正则表达式的详细内容...