过滤外链!

1 protected void Page_Load(object sender, EventArgs e) 
{
string s = @"<a href=""http://www.qq.com"">腾讯</a> <a href=""http://www.163.com"">网易</a> <a href=""http://www.sina.com.cn"">新浪</a>";
MatchEvaluator me = new MatchEvaluator(ABC);
string r = Regex.Replace(s, @"(?is)<a[^>]*href=([""'])(?<href>.*?)\1>.*?</a>", me);
Response.Write(r); Response.End(); }

private string ABC(Match match)
{

if (!match.Groups["href"].Value.ToLower().Contains("www.sina.com.cn"))
return "";
else return match.Value;
}
posted @ 2012-06-13 14:34  互联网Fans  阅读(273)  评论(0编辑  收藏  举报