I'm trying to code a script that removes comments from HTML, except those that begin with [
or !
. For example, the comments below should be removed:
<!-- one line comment -->
<!--
multiple line comment
-->
The following should not be removed:
<!-- ! one line comment -->
<!--! one line comment -->
<!--!
multiple line comment
-->
<!-- !
multiple line comment
-->
<!--
!multiple line comment
-->
<!--[if lt IE 9]>
I'm trying to run the following:
$html = preg_replace('/<!--[\s
]*[^![].*-->/Uis', '', $html);
But it doesn't match the first class of characters (any quantity of spaces and new lines). For example, <!-- !test -->
is removed from HTML, while <!--!test -->
is not.
What's wrong?