Replace the pattern:
(?s)((?!-->).)*<!--|-->((?!<!--).)*
with an empty string.
A short explanation:
(?s) # enable DOT-ALL
((?!-->).)*<!-- # match anything except '-->' ending with '<!--'
| # OR
-->((?!<!--).)* # match '-->' followed by anything except '<!--'
Be careful when processing (X)HTML with regex. Whenever parts of comments occur in tag-attributes or CDATA blocks, things go wrong.
EDIT
Seeing your most active tag is JavaScript, here's a JS demo:
print(
"<div><!--<b>Test</b>-->Test</div>\n<div><!--<b>Test2</b>-->Test2</div>"
.replace(
/((?!-->)[\s\S])*<!--|-->((?!<!--)[\s\S])*/g,
""
)
);
which prints:
<b>Test</b><b>Test2</b>
Note that since JS does not support the (?s)
flag, I used the equivalent [\s\S]
which matches any character (including line break chars).
Test it on Ideone here: http://ideone.com/6yQaK
EDIT II
And a PHP demo would look like:
<?php
$s = "<div><!--<b>Test</b>-->Test</div>\n<div><!--<b>Test2</b>-->Test2</div>";
echo preg_replace('/(?s)((?!-->).)*<!--|-->((?!<!--).)*/', '', $s);
?>
which also prints:
<b>Test</b><b>Test2</b>
as can be seen on Ideone: http://ideone.com/Bm2uJ