ASP实用的两个正则函数
来源:http://www.7dit.com 作者:7dit 发布日期:2008-10-11 02:47:17 点击量:379
<%
function shownew(str,patrn,strRepl)
Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = patrn
shownew = regEx.Replace(str, strRepl)
end function
Response.write shownew("12345sdf32","(\d+)","<b>$1</b>")
' 函数用于替换指定的字符串
%>
Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = patrn
shownew = regEx.Replace(str, strRepl)
end function
Response.write shownew("12345sdf32","(\d+)","<b>$1</b>")
' 函数用于替换指定的字符串
%>
<%
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全局替换。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历 Matches 集合。
RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
Response.write RegExpTest("(\d{10,20}.(jpg|gif))","244234452345234534125.jpgdsfi>?oi93205920123123534643626.gif")
' 函数用于匹配指定的字符串
%>
Copyright © 2005 奇点中文网--7dit.com
闽ICP备05001292号
闽ICP备05001292号
