Regular expression application code in [ASP]

Time:2021-10-18

Today, when changing a B2B e-commerce system, I found that ASP is regular. Although I have used ASP for a long time, I have never used regular expressions. There is a regular function in this system, which is very good. Let me see for myself.

Copy codeThe code is as follows:
<%  
Function RegExpTest(patrn, strng) 
     Dim   regEx,   Match,   Matches    ‘  Create variables.  
     Set   regEx  =  New   RegExp    ‘  Establish regular expressions.  
      regEx.Pattern  =  patrn    ‘  Set the mode.  
     regEx.IgnoreCase  =  False    ‘  Sets whether characters are case sensitive.  
     regEx.Global  =  True    ‘  Set global availability.  
     Set   Matches  =  regEx.Execute(strng)    ‘  Perform a search.  
     For   Each   Match   In   Matches    ‘  Traverse the matching set.  
    On Error Resume Next 
    RetStr = RetStr & Match.Value&”|” 
    Next 
    RegExpTest = RetStr 
End Function 

  str  =  “I come from #5565# ha ha”  
 strInfo = RegExpTest(“#\w+(\((\b[,0-9]+\b)?\))?#”, str) 
 Response.Write(strInfo) 
%> 

Take another example:

Copy codeThe code is as follows:
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