ASP hyperlink and HTML function regular expression revision

Time:2021-4-30

Filter hyperlinks

Copy codeThe 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 codeThe code is as follows:
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
‘Take closed < >
objRegExp.Pattern = “<.+?>”
‘To match
Set Matches = objRegExp.Execute(strHTML)
‘traverse the matching set and replace the matching items
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,””)
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function

Filter all HTML code and whitespace wrapping

Copy codeThe 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 expression to remove script code and HTML code
1、 Make clear the javscript code in the content. The purpose of this code is to remove all the parts contained with < script < / script > tags.
According to the actual needs, it may not meet the requirements. If it is used to block the code submitted by customers, ensure that this step is executed at the end.
A lot of people will still piece together such marks, 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

2、 Clear HTML code from 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 codeThe code is as follows:
< JS jsid = “1” jsname = “remove the interference information in 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(/<img((.|\n)*?)>/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>

Regular filtering functions commonly used in ASP can filter HTML JS style div font

Regular expressions are often used to filter some unnecessary things in developing programs, such as HTML JS style div font. Sometimes it is necessary to filter very few things, sometimes it is necessary to filter several kinds of things. No matter how to filter, it will never change.
This is my collection of some filter functions, can be used to filter you do not need the code. If you need to filter multiple types, you can nest them or integrate the code yourself. However, nesting is not recommended because it is too inefficient.

ASP regular expressions filter all HTML Tags:

Copy codeThe 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 filter tag:
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 expressions filter font Tags:
regEx.Pattern = “<(\/){0,1}font[^<>]*>”
ASP regular expression filter span tag:
regEx.Pattern = “<(\/){0,1}span[^<>]*>”
ASP regular expression filter object tag:
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}”

Regular expression of string replacement:

Copy codeThe code is as follows:
<%
Function ReplaceReg(str,patrn,replStr,Ignor)
‘=========================================
‘parameter explanation:
‘str original string
‘PATRN the string to replace (regular expression)
‘replstr the string to replace with
‘whether ignore is case sensitive (1 is not case sensitive, 0 is case sensitive)
‘=========================================
Dim regex ‘creates a variable.
If Ingor=1 Then Ingor=true else Ingor=false
Set regex = new regexp’creates a regular expression.
Regex. Pattern = pattern ‘setting mode.
Regex. Ignorecase = ignore ‘sets whether to be case sensitive.
regEx.Global=True
Replacereg = regex. Replace (STR, replacestr) ‘.
End Function
‘for example www.xxx.com Replace with < A=“ https://www.jb51.net “> www.jb51.net </a>
Response.Write(ReplaceReg(“developpaerwww.xxx.com”,”www\.xxx\.com”,”<a href=””https://www.jb51.net””>www.jb51.net</a>”,1))
%>

Recommended Today

Design of multiple login users in ABP

scene In the “school management system”, students, parents, teachers, educational administration may log in and do some of their own operations. These users need different attributes. For example, students have student numbers, but teachers don’t. Application users When coding, you often need to get the information of the current login user, which is the application […]