日期:2014-05-17 浏览次数:20401 次
void Main() { string hcontent2=@"<table> <tr><td>aaaaa</td></tr> <tr><td>aabcb</td></tr> <tr><td>bbbb</td></tr> </table>"; foreach(Match m in Regex.Matches(hcontent2, @"(?i)<tr>.*?abc.*?</tr>")) { Console.WriteLine(m.Value); } /* <tr><td>aabcb</td></tr */ }
------解决方案--------------------
目标为什么是:
<tr>
Tar_Candle
</tr>
------解决方案--------------------
void Main() { string hcontent2=@"<table> <tr> 12343 <tr> <tr> 3454afsadf35 <tr> </table> <table> <tr> <table> <tr> Tar_Candle </tr> </table> </tr> <tr> Tar_Abc </tr> <tr> aaa </tr> </table> <table> <tr> adaf </tr> <tr> xys </tr> </table>"; foreach(Match m in Regex.Matches(hcontent2, @"(?is)<tr>((?!</?tr>).)*?Candle((?!</tr>).)*?</?tr>")) { Console.WriteLine(m.Value); } /* <tr> Tar_Candle </tr> */ }