日期:2014-05-18  浏览次数:20800 次

正则表达式匹配:<!-- -->
在一段HTML中,有:
<html>
<head>
<title></title>
</head>
<body>
<script>
<!--
//类似的script可能有0个或多个
-->
</script>
<table>
<tr>
<td>
<!--
……类似的这种注释有很多个
-->
</td>
</tr>
</table>
</body>
</html>

请问如果匹配不是<script>中的那些注释符号?
谢谢。

------解决方案--------------------
(?s)(?<!<script>\n)<!--.*?-->
------解决方案--------------------
效率不高,莫非是这样?

(?sn)(?<!<script>((?!</script>).)*?)<!--.*?-->