ASP使用正则表达式过滤a标签,过滤页面中或提交过来的所有超级链接,使用正则可以准确找出这些链接并加以清除,为了便于使用,青岛星网写成函数,代码如下。
Function RegRemoveHref(HTMLstr)
Set ra = New RegExp
ra.IgnoreCase = True
ra.Global = True
ra.Pattern = "<A[^>]+>(.+?)<\/A>"
RegRemoveHref = ra.replace(HTMLstr,"$1")
END Function
使用方法,假设变量content是包含有链接的字符串,我们可以这样用:
content=RegRemoveHref(content),这样content变量中的所有包含a标签的链接都将被剔除。