Today, when I changed a B2B e-commerce system, I found ASP regular expressions. Although I have been using ASP for a long time, I have never used regular expressions. This system has a good regular function, let's see for yourself.
Copy codeThe Code is as follows:
<%
Function RegExpTest (patrn, strng)
Dim regEx, Match, Matches 'to create a variable.
Set regEx = New RegExp 'to create a regular expression.
RegEx. Pattern = patrn 'setting mode.
RegEx. IgnoreCase = false' is used to determine whether the character is case sensitive.
RegEx. Global = true' to set Global availability.
Set Matches = regEx. Execute (strng) 'to Execute the search.
For Each Match In Matches 'traverses the matching set.
On Error Resume Next
RetStr = RetStr & Match. Value & "|"
Next
RegExpTest = RetStr
End Function
Str = "I come from #5565 # haha"
StrInfo = RegExpTest ("# \ w + (\ B [, 0-9] + \ B )? \))? # ", Str)
Response. Write (strInfo)
%>
Let's look at 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