Regular Expressions in [asp] Use Code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.