建站常识

asp正则表达式过滤标签html,style ,div,font,span,Object,iframe

发布时间 | 2017/11/24  点击 | 

<%

'过滤 所有 html :

Function ReplaceHtml(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "<\/*[^<>]*>"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceHtml = tmpReStr

End Function

'过滤 style :

Function ReplaceStyleTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "(<style)+[^<>]*>[^\0]*(<\/style>)+"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceStyleTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 层 div :

Function ReplaceDivTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "<(\/){0,1}div[^<>]*>"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceDivTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 链接 a :

Function ReplaceATag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "<(\/){0,1}a[^<>]*>"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceATag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 字体 font :

Function ReplaceFontTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "<(\/){0,1}font[^<>]*>"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceFontTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 span :

Function ReplaceSpanTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "<(\/){0,1}span[^<>]*>"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceSpanTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 Object :

Function ReplaceObjectTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "<object.*?/object>"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceObjectTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 iframe:

Function ReplaceIFrameTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "(<iframe){1,}[^<>]*>[^\0]*(<\/iframe>){1,}"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceIFrameTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 script:

Function ReplaceScriptTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "(<script){1,}[^<>]*>[^\0]*(<\/script>){1,}"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceScriptTag = tmpReStr

   Set regEx = Nothing

End Function

'过滤 Class :

Function ReplaceClassTag(ConStr)

   Dim tmpReStr, regEx

   tmpReStr = CStr(ConStr)

   Set regEx = New RegExp

   regEx.Pattern = "(class=){1,}(""|\'){0,1}\S+(""|\'|>|\s){0,1}"

   regEx.IgnoreCase = True

   regEx.Global = True

   tmpReStr = regEx.Replace(tmpReStr, "")

   ReplaceClassTag = tmpReStr

   Set regEx = Nothing

End Function

%>

相关信息