I have come up with the following regex to be able to extract quotes from text:
"(?P<quote>.+?(?<![^\\]\\))"
It works ok on the above: https://regex101.com/r/NVjtW4/1.
However, I was wondering if there were any other "techniques" you could use to extract quoted texts. Perhaps with the following constraints:
- Not using
.+?
- Without using a negative lookbehind (perhaps a negated character class instead).
Basically my question here is not, "What is the one way to do it?", but "What might be other alternatives" so I can see different possible approaches to solve what to me feels like a difficult and tricky regex to craft (escape one \
but not two \\
, etc.)
Additionally, I want to check to see if there are an odd number of escapes preceding the quote:
".*?(?<=(\\{2})*)"
But this gives me an error of "* A quantifier inside a lookbehind makes it non-fixed width"
. Another one I had is:
"[^((\\{2})*")]+"
But this also doesn't match escaped quotes.