I have a regex that I want to match a certain pattern. However, I don't want it to match that pattern if it exists between HTML comment blocks
What I have currently is:
(?<!<!--)pattern(?!-->)
However that only works when the pattern is exactly between comment blocks but not in the case of something like:
<!-- foo pattern -->
But if I do:
(?<!<!--.*)pattern(?!-->)
then this case doesn't work:
<!-- some commented out stuff --> pattern
I think if I could express (everything except -->)*? within the negative look behind it would work but I'm unsure of the proper syntax or if that's allowed.
(?<!<!--[^<>]*)pattern(?![^<>]*-->)might work then. What you ask for is(?<!(?:(?!<!--|-->).)*)pattern(?!(?:(?!<!--|-->).)*-->)between comment blocks, if you have 400 comment blocks or 2, all it takes is to have a comment block at the top, and one at the bottom.(?:<!--comment-->.*<!--comment-->)?.*?patternit finds pattern no matter what. You could match both, to move past comments like this(?:<!--comment-->.*<!--comment-->)|(pattern)then see if group 1 matched. It's the only way.