asp 过滤尖括号内所有内容的正则代码


当然这应该属于正常过滤手法,而还有一种过滤HTML标签的最终极手法,则是将一对尖括号及尖括号中的所有字符均替换不显示,该方法对于内容中必须描述有关尖括号内容过滤过头了。
  不过,总归是有需要将所有尖括号中内容全部替换的时候,很显然是需要进行正则的,有两种代码,第一种如下:

复制代码 代码如下:

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
set re=nothing
End Function

  第二种:
复制代码 代码如下:

Function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="<(.[^>]*)>"
str=re.replace(str,"")
nohtml=str
set re=nothing
End Function

简单的应用:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3