asp.net正则表达式去除a标签

if (drr["allow_a"].ToString() == "False")
{
cont = dr["news_Content"].ToString();

ctss = Regex.Replace(cont, @"<[a|A]s*[^>]*>(.*?)</[a|A]>", "$1");
}

(1)string ctss = Regex.Replace(cont, @"<[a|A]s*[^>]*>.*?</[a|A]>", "");

这种方式可以去除a标签内部的所有文字,eg:<p><a href='#'>哈哈哈哈</a></p>

输出:<p></p>

(2)string ctss = Regex.Replace(cont, @"<[a|A]s*[^>]*>(.*?)</[a|A]>", "$1");

这种方式输出:<a href='#'>哈哈哈哈哈</a>

输出:哈哈哈哈哈

原文地址:https://www.cnblogs.com/tuoxiong/p/5910392.html