正则表达式过滤html标签

/*过滤掉的信息包括html的任何标签和属性*/
 1  public static string ClearHtmlCode(string text)
2 {
3 text = text.Trim();
4 if (string.IsNullOrEmpty(text))
5 return string.Empty;
6 text = Regex.Replace(text, "[/s]{2,}", ""); //过滤两个或两个以上的空格
7 text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|/n)*?>)", ""); //过滤换行
8 text = Regex.Replace(text, "(/s*&[n|N][b|B][s|S][p|P];/s*)+", ""); //过滤空格
9 text = Regex.Replace(text, "<(.|/n)*?>", "\t");
10 text = Regex.Replace(text, "/<//?[^>]*>/g", string.Empty);
11 text = Regex.Replace(text, "/[ | ]* /g", string.Empty);
12 text = text.Replace("'", "''");
13 text = Regex.Replace(text, "/ [/s| | ]* /g", string.Empty);
14 return text;
15 }
posted @ 2011-11-05 10:01  幸福~伞  阅读(550)  评论(0编辑  收藏  举报