fork download
  1. <?php
  2.  
  3. $re = '~<!--\s*+(?!!\N*\n).*?-->~s';
  4. $str = "<!-- one line comment -->\n\n<!--\nmultiple line comment\n-->\n\nThe following should not be removed:\n\n<!-- ! one line comment -->\n\n<!--! one line comment -->\n\n<!--!\nmultiple line comment\n-->\n\n<!-- !\nmultiple line comment\n-->\n\n<!--\n!multiple line comment\n-->\n\n<!--[if lt IE 9]>";
  5. preg_match_all($re, $str, $matches);
  6. print_r($matches);
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => <!-- one line comment -->
            [1] => <!--
multiple line comment
-->
        )

)