您的位置:首页 > 运维架构 > 网站架构

去除网站中HTML标签的正则表达式

2010-05-24 16:44 627 查看
string str = a.ToString();

str = Regex.Replace(str, @"</?span[^>]*>", "", RegexOptions.IgnoreCase);

str = Regex.Replace(str, @"&#[^>]*;", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?marquee[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?object[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?param[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?embed[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?table[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @" ","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?tr[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?th[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?p[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?a[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?img[^>]*>","",RegexOptions.IgnoreCase);

str = Regex.Replace(str, @"</?tbody[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?li[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?span[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?div[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?th[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?td[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?script[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"(javascript|jscript|vbscript|vbs):", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"on(mouse|exit|error|click|key)", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"<//?xml[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"<//?[a-z]+:[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?font[^>]*>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?b[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?u[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?i[^>]*>","",RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"</?strong[^>]*>","",RegexOptions.IgnoreCase);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: