I am trying to use a regexp to match strings, e.g. a pattern that matches these kinds of quoted strings:
"test"
or 'test'
or 'test with "quote"'
or "test with 'quote'"
This pattern matches all those,
"\\(\"\\|'\\)[^\\1]+?\\1"
but, it fails on "test\n"
(and other control characters like \t
and \r
). I don't understand why \n
(a newline) is so special it doesn't match [^\\1]
which I thought was a character that doesn't match the opening quote. Is this expected?
If I replace [^\\1]
with .
then it works on all the strings, including the one with \n
in it. I guess it is ok because +?
makes it nongreedy so it seems to not over match.
Note, this question originated from How to highlight in different colors for variables inside `fstring` on python-mode.