ASP Hyperlink and regular expression correction for HTML Functions

Source: Internet
Author: User

Filter hyperlink CopyCode The Code is as follows: function regremovehref (htmlstr)
Set Ra = new Regexp
RA. ignorecase = true
RA. Global = true
RA. pattern = "<A [^>] +> (. + ?) <\/A>"
Regremovehref = Ra. Replace (htmlstr, "$1 ")
End Function

filter all HTML code
copy Code the code is as follows: function removehtml (strhtml)
dim objregexp, match, matches
set objregexp = new Regexp
objregexp. ignorecase = true
objregexp. global = true
'get closed <>
objregexp. pattern = "<. +?> "
'match
set matches = objregexp. execute (strhtml)
'traverses the matching set and replaces the matched item
for each match in matches
strhtml = Replace (strhtml, match. value, "")
next
removehtml = strhtml
set objregexp = nothing
end function

filter all HTML code and space line breaks copy Code the code is 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 each match in matches
strhtml = Replace (strhtml, match. value, "")
next
objregexp. pattern = "(\ r | \ n | \ r \ n | \ t |)"
set matches = objregexp. execute (strhtml)
for each match in matches
strhtml = Replace (strhtml, match. value, "")
next
removehtml = strhtml
set objregexp = nothing
end function

ASP uses regular expressions to remove script and HTML code
I. Clear the javsscript code in the content. The purpose of this Code is to remove all the parts included by marking with <SCRIPT </SCRIPT>.
Based on actual needs, it may not meet the requirements. If this step is used to shield the client from submitting code, ensure that this step is executed at the end.
A lot of people will also put together such a mark, so be careful.Copy codeThe Code is 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

Ii. Clear HTML code from the content
Copy codeThe Code is 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 The Code is as follows: <JS jsid = "1" jsname = "remove interference information from the content page"> <! [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 (/<tr (. | \ n) *?)> /Ig, "<br> ");
Ss = ss. Replace (/(<\/tr>)/ig ,"");
Ss = ss. Replace (/<nobr (. | \ n) *?)> /Ig, "<br> ");
Ss = ss. Replace (/<nobr (. | \ n) *?)> /Ig ,"");
Ss = ss. Replace (/(<\/nobr>)/ig ,"");
Ss = ss. Replace (/<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>

Common Regular Expression filtering functions in ASP can filter html js style Div font.

DevelopmentProgramRegular Expressions are often used to filter out unnecessary things, such as html js style Div font. Sometimes it is necessary to filter out a few items, and sometimes it is necessary to filter several types, no matter how it is filtered, it is always the same.
These are some of my favorite filter functions that can be used to filter out unnecessary code. If you need to filter multiple types of data, you can use them in nesting mode or integrate the code yourself. However, nesting is not recommended because it is too inefficient.

Asp Regular Expression filters all HTML tags: copy Code the code is 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 filtering STYLE tag:
RegEx. pattern = "( ] *> [^ \ 0] * (<\/style>) + "
Asp Regular Expression filtering layer Div Tag:
RegEx. pattern = "<(\/) {0, 1} Div [^ <>] *>"
Asp Regular Expression Filter link a tag:
RegEx. pattern = "<(\/) {0, 1} A [^ <>] *>"
Asp Regular Expression Filter font MARK:
RegEx. pattern = "<(\/) {0, 1} font [^ <>] *>"
Asp Regular Expression Filter span tag:
RegEx. pattern = "<(\/) {0, 1} span [^ <>] *>"
Asp Regular Expression filters object tags:
RegEx. pattern = " "
Asp Regular Expression Filtering IFRAME tag:
RegEx. pattern = "( ] *> [^ \ 0] * (<\/iframe>) {1 ,} "
Asp Regular Expression filtering Script:
RegEx. pattern = "( ] *> [^ \ 0] * (<\/SCRIPT>) {1 ,} "
Asp Regular Expression filtering class Tag:
RegEx. pattern = "(class =) {1,} (" "| \ ') {0, 1} \ s + (" "| \' | >|\ S) {0, 1} "

Regular Expression for replacing replace with a string: copy Code the code is as follows: <%
function replacereg (STR, patrn, replstr, ignor)
'========================================== =====< br> 'parameter explanation:
'str original string
'patrn string to be replaced (regular expression)
'replstr string to be replaced
'ignore' case sensitive (1 case insensitive, 0 case sensitive)
'========================================== =====< br> dim RegEx 'create a variable.
If ingor = 1 then ingor = true else ingor = false
set RegEx = new Regexp 'creates a regular expression.
RegEx. pattern = patrn 'sets the mode.
RegEx. ignorecase = ignor 'is used to set Case sensitivity.
RegEx. Global = true
replacereg = RegEx. Replace (STR, replstr) 'is replaced.
end function
'For example, replace www.xxx.com with www.jb51.net
response. write (replacereg (" www.www.xxx.com", "www \. XXX \. com "," www.jb51.net ", 1)
%>

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.