Today in the change of a business-to-business e-commerce system, found that the ASP is positive, although using ASP for a long time, but never used regular expression, this system has a regular function is very good, I see it.
Copy Code code as follows:
<%
Function regexptest (PATRN, STRNG)
Dim regEx, Match, matches ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = False ' Sets whether the character case is case-sensitive.
Regex.global = True ' Sets global availability.
Set matches = Regex.execute (strng) ' performs a search.
For the match in matches ' traversal matching collection.
On Error Resume Next
Retstr = retstr & match.value& "|"
Next
Regexptest = Retstr
End Function
str = "I'm from #5565# haha"
Strinfo = Regexptest ("#\w+" ((\b[,0-9]+\b))? # ", str)
Response.Write (Strinfo)
%>
Look at one more example:
Copy Code code 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