In other words, I have a string like:
\"anything, escaped double-quotes: \\\", yep\" anything here NOT to be matched.
How do I match everything inside the qu
No lookbehind necessary:
"([^"]|\\")*"
So: match quotes, and inside them: every character except a quote ([^"]
) or an escaped quote (\\"
), arbitrarily many times (*
).
"Not preceded by" translates directly to "negative lookbehind", so you'd want (?<!\\)"
.
Though here's a question that may ruin your day: what about the string "foo\\"
? That is, a double-quote preceded by two backslashes, where in most escaping syntaxes we would be wanting to negate the special meaning of the second backslash by preceding it with the first.
That sort of thing is kind of why regexes aren't a substitute for parsers.