正则表达式,以避免剥离IE条件标签

时间:2015-07-30 11:46:06

标签: php regex

我在PHP中使用正则表达式剥离我的HTML注释。

$html = preg_replace('/<!--(.*)-->/Uis', '', $html);

但是,我不希望正则表达式删除我有条件的IE TAGS

<!--[if lte IE 6]><html class="ie6 no-js">
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

有没有简单的方法可以做到这一点?

修改 为方便起见,我在此处添加了相关的HTML代码: http://pastebin.com/dPGHHXjU (要么) 在这里:https://regex101.com/r/yS8zM6/1

提前致谢

2 个答案:

答案 0 :(得分:0)

也许this one

<!--(?!\[).*?-->

希望有所帮助。

答案 1 :(得分:0)

我从另一个帖子得到答案:

$html = preg_replace('~<!--(?!<!)[^\[>].*?-->~s','', $html);

这个正则表达式效果很好。 (但我不确定它的作用)

参考文献:https://stackoverflow.com/a/11337360/1163642(Allen Pestaluky回答的评论)

我在这里添加了一个演示:https://regex101.com/r/yS8zM6/2