62,074
社区成员
发帖
与我相关
我的任务
分享
string test = @"<table ....>xxxxx
xxxx
</table>
相关文字
...
<table>
<tr>
<td>
<script.....>//这里是script的广告代码,我想只取得这里的表格,并用""替换掉,但这里有二个表格的话取得就会
二个表格最后一直取出来,如何解决啊,请各位高手指点一下,谢谢了:)
</script>
</td></tr></table>
";
Match m = Regex.Match(test, @"<table[^>]*>(?:(?!<table[^>]*>)[\s\S])*?</script>(?:(?!<table[^>]*>)[\s\S])*?</table>", RegexOptions.IgnoreCase);
if (m.Success)
MessageBox.Show(m.Value);
string result = Regex.Replace(str, @"<table[^>]*>[\s\S]*?</table>", myEvaluator, RegexOptions.IgnoreCase);
private string myEvaluator(Match m)
{
if (m.Value.ToLower().IndexOf("</script>") > -1)
return "";
return m.Value;
}
<table ....>xxxxx
xxxx
</table>
相关文字
...
<table>
<tr>
<td>
<script.....>//这里是script的广告代码,我想只取得这里的表格,并用""替换掉,但这里有二个表格的话取得就会
把第一个表格一直到第二个表格最后一直取出来,如何解决啊,请各位高手指点一下,谢谢了:)
</script>
</td></tr></table>
<table[\s\S]+?<script[^>]+?>[\s\S]+?</script>[\s\S]+?</table>
<table[\s\S]+?<script>[\s\S]+?</script>[\s\S]+?</table>
<table[\s\S]+?</table>