C#常用正则过滤
//string regexstr = @"<[^>]*>"; //去除所有的标签 //@"<script[^>]*?>.*?</script >" //去除所有脚本,中间部分也删除 html = Regex.Replace(html, "<script[^>]*>([\\s\\S]*?)</script>", "", RegexOptions.IgnoreCase);
html = Regex.Replace(html, "<a([^>]*)>([^<]+)</a>", "$2", RegexOptions.IgnoreCase);//过滤a链接,只留a内容 // string regexstr = @"<img[^>]*>"; //去除图片的正则 // string regexstr = @"<(?!br).*?>"; //去除所有标签,只剩br // string regexstr = @"<table[^>]*?>.*?</table>"; //去除table里面的所有内容 string regexstr = @"<(?!img|br|p|/p).*?>"; //去除所有标签,只剩img,br,p str = Regex.Replace(str, regexstr, string.Empty, RegexOptions.IgnoreCase);