I use the below regular expression to only match a given character sequence if it is not surrounded by quotes - that is, if it is followed by an even number of quotes (using a positive lookahead) until the end of the string.
Say I want to match the word section
only if it is not between quotes:
\bsection\b(?=[^"]*(?:"[^"]*"[^"]*)*$)
How would I extend this to take escaped quotes into consideration? That is, if I insert a \"
between the quotes in the linked example, the results stay the same.
Using pcre could skip the quoted stuff:
In string regex pattern have to triple-escape the backslash, like
\\\\
to match a literal backslash in the lookbehind. Or in a single quoted pattern double escaping it would be sufficient for this case.See test at regex101.