当前位置:主页 > 查看内容

[asp]中的正则表达式运用代码

发布时间:2021-07-19 00:00| 位朋友查看

简介:今天在改一套b2b的电子商务系统时,发现ASP正则,虽然用ASP很久了,但从来没用过正则表达式,这套系统中有个正则的函数很不错,自己看吧。 复制代码 代码如下: % FunctionRegExpTest(patrn,strng) DimregEx,Match,Matches'建立变量。 SetregEx=NewRegExp'建……
今天在改一套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

原文链接:https://m.jb51.net/article/10680.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐