zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

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

2023-06-13 09:13:57 时间
今天在改一套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