分享

C#过滤Html标记

 若生安饶 2010-12-22
public string RemoveHtml(string html)
  {
   Regex regex1 = new Regex(@"<script[\s\S]+</script *>", RegexOptions.IgnoreCase);
   Regex regex2 = new Regex(@" href *= *[\s\S]*script *:",RegexOptions.IgnoreCase);
   Regex regex3 = new Regex(@" no[\s\S]*=", RegexOptions.IgnoreCase);
   Regex regex4 = new Regex(@"<iframe[\s\S]+</iframe *>", RegexOptions.IgnoreCase);
   Regex regex5 = new Regex(@"<frameset[\s\S]+</frameset *>", RegexOptions.IgnoreCase);
   Regex regex6 = new Regex(@"\<img[^\>]+\>", RegexOptions.IgnoreCase);
   Regex regex7 = new Regex(@"</p>", RegexOptions.IgnoreCase);
   Regex regex8 = new Regex(@"<p>", RegexOptions.IgnoreCase);
   Regex regex9 = new Regex(@"<[^>]*>",RegexOptions.IgnoreCase);
   html = regex1.Replace(html, "");
   html = regex2.Replace(html, "");
   html = regex3.Replace(html, " _disibledevent=");
   html = regex4.Replace(html, "");
   html = regex5.Replace(html, "");
   html = regex6.Replace(html, "");
   html = regex7.Replace(html, "");
   html = regex8.Replace(html, "");
   html = regex9.Replace(html, "");
   html = html.Replace(" ", "");
   html = html.Replace("</strong>", "");
   html = html.Replace("<strong>", "");
   return html;
  }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约