I'm trying to add a special markup to Python documentation strings in emacs (python-mode).
Currently I'm able to extract a single line with:
(font-lock-add-keywords
'python-mode
'(("\\(\"\\{3\\}\\.+\"\\{3\\}\\)"
1 font-lock-doc-face prepend)))
This works now:
"""Foo"""
But as soon there is a newline like:
"""
Foo
"""
It doesn't work anymore. This is logical, since .
doesn't include newlines (\n
).
Should I use a character class?
How can I correct this regular expression to include everything between """ """
?
Thanks in advance!
According to regex101.com \s : Matches any space, tab or newline character.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
"\\(\"\\{3\\}\\(.*\n?\\)*?\"\\{3\\}\\)"
The "*?" construct is the non-greedy version of "*".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With