日期:2014-05-17  浏览次数:20804 次

求一正则过滤远程URL,保留本地URL
现在有一需求:用户在编辑框中输入内容后,我需要将取得的内容中的非本站网址屏蔽掉,而保留本地的或者指定的网址

比如:

内容中含有"<img src="http://www.baidu.com/images/1.gif"><a href="http://www.qq.com">http://www.qq.com</a><a href="http://www.xiuyidian.com">http://www.xiuyidian.com</a><img src="http://www.aa.com/images/2.gif">"

我需要用正则过滤掉<img src="http://www.baidu.com/images/1.gif">,将<a href="http://www.qq.com">http://www.qq.com</a>替换换成没有连接的网址:http://www.qq.com,而保留<a href="http://www.xiuyidian.com">http://www.xiuyidian.com</a><img src="http://www.aa.com/images/2.gif">这两个

希望正则过滤完成后的最终的结果是“http://www.qq.com<a href="http://www.xiuyidian.com">http://www.xiuyidian.com</a><img src="http://www.aa.com/images/2.gif">”


希望有正则高手帮忙一下,谢谢哈!

------解决方案--------------------
Function IsValidUrl(str) 
Dim regEx 
Set regEx = New RegExp 
regEx.Pattern = "http(s)?://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?" 
IsValidUrl = regEx.Test(str) 
End Function