ASP hyperlink and HTML function regular expression modifier-regular expression

Source: Internet
Author: User
Tags modifier
Filter Hyperlinks
Copy Code code as follows:

Function Regremovehref (HTMLSTR)
Set RA = New RegExp
Ra. IgnoreCase = True
Ra. Global = True
Ra. Pattern = "<A[^>]+> (. +?) <\/A> "
Regremovehref = Ra.replace (Htmlstr, "$")
End Function


Filter All HTML code
Copy Code code as follows:

Function removehtml (strhtml)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
Objregexp.ignorecase = True
Objregexp.global = True
' Take the closed <>
Objregexp.pattern = "<.+?>"
' to match
Set matches = Objregexp.execute (strhtml)
' Iterate through the matching set and replace the matching item
For the Match in matches
Strhtml=replace (Strhtml,match.value, "")
Next
Removehtml=strhtml
Set objRegExp = Nothing
End Function

Filter all HTML code and Space line wrapping
Copy Code code as follows:

Function removehtml (strhtml)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
Objregexp.ignorecase = True
Objregexp.global = True
Objregexp.pattern = "<.+?>"
' Objregexp.pattern = ' (\r|\n|\r\n| |\t|) "
Set matches = Objregexp.execute (strhtml)
For the Match in matches
Strhtml=replace (Strhtml,match.value, "")
Next
Objregexp.pattern = "(\r|\n|\r\n| |\t|)"
Set matches = Objregexp.execute (strhtml)
For the Match in matches
Strhtml=replace (Strhtml,match.value, "")
Next
Removehtml=strhtml
Set objRegExp = Nothing
End Function

ASP uses regular expressions to get rid of script code and HTML code
A clear Javsscript code in the content of this code is to remove all parts contained in the <script </script> tag.
Depending on the actual needs, it may not meet the requirements. If you use it to mask the customer's submission code, you should ensure that this is done at the final stage.
Many people will also put together such a mark, should be careful.
Copy Code code as follows:

Function Clearjscode (Origincode)
Dim Reg
Set reg = New RegExp
Reg. Pattern = "<SCRIPT[^<]*</SCRIPT>"
Reg. IgnoreCase = True
Reg. Global = True
Clearjscode = Reg. Replace (Origincode, "")
End Function

second, clear the content of the HTML code
Copy Code code as follows:

Function Clearhtmlcode (Origincode)
Dim Reg
Set reg = new RegExp
Reg. Pattern = "<[^>]*>"
Reg. IgnoreCase = True
Reg. Global = True
Clearhtmlcode = Reg. Replace (Origincode, "")
End Function

Copy Code code as follows:

<js jsid= "1" jsname= "removing interference information from content pages" ><! [cdata[
var sourcehtml=function () {/*%s*/}.tostring (). Slice (13,-3);
Parser9527=function ()
{
var ss=sourcehtml;
Ss=ss.replace (/<.*?>/ig, "");
Ss=ss.replace (/(\r|\n|\r\n| |\t|) /ig, "");
Ss=ss.replace (/(<\/a>)/ig, "");
Ss=ss.replace (/<a (. | \ n) *?) >/ig, "");
Ss=ss.replace ("_ NetEase News Center", "");
/*
Ss=ss.replace (/<iframe (. | \ n) *?) <\/iframe>/ig, "");
Ss=ss.replace (/<script (. | \ n) *?) <\/script>/ig, "");
Ss=ss.replace (/<address (. | \ n) *?) <\/address>/ig, "");
Ss=ss.replace (/(<\/a>)/ig, "");
Ss=ss.replace (/<a (. | \ n) *?) >/ig, "");
Ss=ss.replace (/<select (. | \ n) *?) <\/select>/ig, "");
Ss=ss.replace (/<table (. | \ n) *?) <\/table>/ig, "");
Ss=ss.replace (//ig, "");
Ss=ss.replace (/<table (. | \ n) *?) >/ig, "");
Ss=ss.replace (/(<\/TABLE>)/ig, "");
Ss=ss.replace (/&LT;TR (. | \ n) *?) >/ig, "<BR>");
Ss=ss.replace (/(<\/TR>)/ig, "");
Ss=ss.replace (/&LT;NOBR (. | \ n) *?) >/ig, "<BR>");
Ss=ss.replace (/&LT;NOBR (. | \ n) *?) >/ig, "");
Ss=ss.replace (/(<\/nobr>)/ig, "");
Ss=ss.replace (/&LT;TD (. | \ n) *?) >/ig, "");
Ss=ss.replace (/(<\/TD>)/ig, "");
Ss=ss.replace (/<span id= (. | \ n) *?) <\/small>/ig, "");
Ss=ss.replace (/<div (. | \ n) *?) >/ig, "");
Ss=ss.replace (/(<\/div>)/ig, "");
*/
return SS;
}
parser9527 ();
]]></js>

ASP Common Regular filter function can filter HTML JS style div font

Development program, often use regular expression to filter some unwanted things, such as HTML JS style div font, sometimes need to filter very individual, and sometimes need to filter several kinds, no matter how filtered, same.
This is my collection of some filter functions, can be used to filter the code you do not need. If you need to filter a variety of, you can nest use, you can also integrate the code. Nested use is not recommended, however, because it is too inefficient.

An ASP regular expression filters all HTML tags:
Copy Code code as follows:

Function losehtml (CONTENTSTR)
Dim Clstemplosestr,regex
Clstemplosestr = Cstr (CONTENTSTR)
Set regEx = New RegExp
Regex.pattern = "<\/*[^<>]*>"
Regex.ignorecase = True
Regex.global = True
Clstemplosestr = Regex.Replace (Clstemplosestr, "")
losehtml = Clstemplosestr
End Function



ASP Regular Expression filter style tags:
Regex.pattern = "(<style) +[^<>]*>[^\0]* (<\/style>) +"
ASP Regular Expression filter-layer div tag:
Regex.pattern = "< (\/) {0,1}div[^<>]*>"
ASP Regular expression Filter Link a tag:
Regex.pattern = "< (\/) {0,1}a[^<>]*>"
ASP Regular Expression Filter fonts font Tags:
Regex.pattern = "< (\/) {0,1}font[^<>]*>"
ASP Regular Expressions Filter span tags:
Regex.pattern = "< (\/) {0,1}span[^<>]*>"
ASP Regular Expressions Filter Object tags:
Regex.pattern = "<object.*?/object>"
ASP Regular Expressions Filter iframe Tags:
Regex.pattern = "(<iframe) {1,}[^<>]*>[^\0]* (<\/iframe>) {1,}"
ASP Regular Expression Filter script:
Regex.pattern = "(<script) {1,}[^<>]*>[^\0]* (<\/script>) {1,}"
ASP Regular Expression Filter Class tag:
Regex.pattern = "(class=) {1,} (" |\ ') {0,1}\s+ ("|\ ' |>|\s) {0,1}"

String replaces the regular expression of replace:
Copy Code code as follows:

<%
Function Replacereg (Str,patrn,replstr,ignor)
'=========================================
' Parameter explanation:
' Str the original string
' Patrn the string to replace (regular expression)
' Replstr to be replaced with a string
' Ignor is case-sensitive (1 does not differentiate, 0 differentiates)
'=========================================
Dim regEx ' establishes a variable.
If ingor=1 Then ingor=true Else ingor=false
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = Ignor ' setting is case-sensitive.
Regex.global=true
Replacereg = Regex.Replace (str,replstr) ' for replacement.
End Function
' For example, replace www.xxx.com with <a href= ' http://www.jb51.net ' >www.jb51.net</a>
Response.Write (Replacereg Community www.xxx.com, "www\.xxx\.com", "<a href=" "Http://www.jb51.net" ">www.jb51.net" </a> ", 1))
%>
Related Article

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.