以下用C#这两个正则表达式TABLE我怎么都去不掉,
//            string temp = System.Text.RegularExpressions.Regex.Replace(str,"<TABLE.*?>(.*)?</TABLE>","");
           string temp = System.Text.RegularExpressions.Regex.Replace(str,"<TABLE.*?>[\\s\\S]*?</TABLE>","");
string str=@"<TABLE 
      style="BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; MARGIN: 0px 8px 8px 0px; BORDER-LEFT: #999 1px solid; BORDER-BOTTOM: #999 1px solid" 
      cellSpacing=0 cellPadding=0 width=300 border=0>
        
        <TR>
          <TD align=middle><IMG src="../../../../img/2007-01/24/xin_4501042410542722582421.jpg" border=0></TD></TR>
        <TR>
          <TD class=px12 
          style="PADDING-RIGHT: 3px; PADDING-LEFT: 8px; PADDING-BOTTOM: 3px; LINE-HEIGHT: 18px; PADDING-TOP: 6px" 
          align=left bgColor=#e0e0c9>今年春运客流提前到来,昨天广州火车站广场已人流汹涌。 骆昌威 
        摄</TD></TR></TABLE>";

解决方案 »

  1.   

    Regex rx = new Regex(@"(<\/?(?!table)[^>\/]*)\/?>|<![^>]+>", RegexOptions.IgnoreCase);如果还有其他,这样 
    Regex rx = new Regex(@"(<\/?(?!td|tr|u|table|img)[^>\/]*)\/?>|<![^>]+>", RegexOptions.IgnoreCase);
      

  2.   

    <IMG src=../../../../img/2007-01/24/xin_4501042410542722582421.jpg border=0>这个没有去掉啊
      

  3.   

    楼主正则表达式的问题出在<TABLE.*?>这个“.”上,因为要替换的字符串中<TABLE后是个回车,而“.”是不能匹配回车符的,换成这样就可以了string temp = System.Text.RegularExpressions.Regex.Replace(str,"<TABLE[\\s\\S]*?>[\\s\\S]*?</TABLE>","",RegexOptions.IgnoreCase);
      

  4.   

    lz只要去TABLE,TR,TD还保留?
      

  5.   

    如果只去TABLE的话就是这样:  string temp = System.Text.RegularExpressions.Regex.Replace(str,@"<TABLE[\s\S]*?>([\s\S]*?)</TABLE>","$1");
      

  6.   

    如果只保留文字的话: string temp = System.Text.RegularExpressions.Regex.Replace(str,@"<[^>]*>","");
      

  7.   

    Click the link to solve your problem.Good luck!
      

  8.   

    比如想这样的呢<p>我的CSDN</p> <table class="btn"><tr><td class="x811">One Two</td></tr></table>这样怎么去掉后只剩下 <p>我的CSDN</p>One Two  请教高手