熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

正則表達式過濾html標簽對

2022-06-13   來源: .NET編程 

  public string DealHtml(string str)

  {

  //str = RegexReplace(str @\<(img)[^>]*>|<\/(img)> RegexOptionsIgnoreCase);

  str = RegexReplace(str @\<(table|tbody|tr|td|th)[^>]*>|<\/(table|tbody|tr|td|th)> RegexOptionsIgnoreCase);

  str = RegexReplace(str @\<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)> RegexOptionsIgnoreCase);

  //str = RegexReplace(str @\<(font|i|u|h[]|s)[^>]*>|<\/(font|i|u|h[]|s)> RegexOptionsIgnoreCase);

  //str = RegexReplace(str @\<(style|strong)[^>]*>|<\/(style|strong)> RegexOptionsIgnoreCase);

  //str = RegexReplace(str @\<a[^>]*>|<\/a> RegexOptionsIgnoreCase);

  //str = RegexReplace(str @\<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)> RegexOptionsIgnoreCase);

  str = RegexReplace(str @\<br[^>]* RegexOptionsIgnoreCase);

  str = strReplace(<br> );

  return str;

  }


From:http://tw.wingwit.com/Article/program/net/201311/13195.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.