HTML comments may use inline JavaScript as special blocks for old browsers that don’t support JS code. These blocks look like this:
<!--
some js code
//-->
I want to distinguish ‘true’ html comments from such in JS code. I’ve written this regex:
/<!--[^//]*?-->/g
So I want to exclude matches with a double slash inside, but the regex regards // as a character set of / and /, not as entire double slash //. What can I do?
Character classes, as you noted, only match a single character, so you can’t use them here. But you can make use of negative lookahead assertions:
(assuming this is JavaScript).
Explanation: