Remove text between two HTML comments. Well, one way is to make use of assertions. By using look behind and look ahead assertions (they are not included in any matches), you can grab what is not part of them: $tmp_tpl = preg_replace(‘#(?<=<!–COMMENTBOX–>).+(?=<!–ENDCOMMENTBOX–>)#’, ”, $tmp_tpl); Of course, to test this out, when you say echo $tmp_tpl, …