[asp]中的正則表達(dá)式運(yùn)用代碼
更新時(shí)間:2007年08月01日 19:45:16 作者:
今天在改一套b2b的電子商務(wù)系統(tǒng)時(shí),發(fā)現(xiàn)ASP正則,雖然用ASP很久了,但從來沒用過正則表達(dá)式,這套系統(tǒng)中有個(gè)正則的函數(shù)很不錯(cuò),自己看吧。
<%
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立變量。
Set regEx = New RegExp ' 建立正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = False ' 設(shè)置是否區(qū)分字符大小寫。
regEx.Global = True ' 設(shè)置全局可用性。
Set Matches = regEx.Execute(strng) ' 執(zhí)行搜索。
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
復(fù)制代碼 代碼如下:
<%
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立變量。
Set regEx = New RegExp ' 建立正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = False ' 設(shè)置是否區(qū)分字符大小寫。
regEx.Global = True ' 設(shè)置全局可用性。
Set Matches = regEx.Execute(strng) ' 執(zhí)行搜索。
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)
%>
再看一例:
復(fù)制代碼 代碼如下:
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
相關(guān)文章
JavaScript RegExp 正則表達(dá)式對象詳細(xì)說明
RegExp 對象表示正則表達(dá)式,它是對字符串執(zhí)行模式匹配的強(qiáng)大工具。2010-12-12
密碼強(qiáng)度的正則表達(dá)式兩種方案JS總結(jié)篇
本文給出了兩個(gè)密碼強(qiáng)度的正則表達(dá)式方案,一個(gè)簡單,一個(gè)更復(fù)雜和安全。并分別給出了兩個(gè)方案的解析和測試程序。對密碼強(qiáng)度正則表達(dá)式的兩種方案感興趣的朋友跟隨腳本之家一起看看吧2018-03-03
js正則表達(dá)式中的單行模式與多行模式實(shí)例分析
這篇文章主要介紹了js正則表達(dá)式中的單行模式與多行模式,實(shí)例分析了js正則表達(dá)式中實(shí)現(xiàn)單行模式與多行模式的技巧,需要的朋友可以參考下2015-01-01

