Siehe auch: https://docs.python.org/3/reference/lex ... ml#strings
Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters.
Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters.
Das regex Modul in Python scheint das aber nicht zu stören. Bzw. sind die Backslashes ja keine Zeichen, sondern bereits Escape-Einleitungen. Also wenn ich tatsächlich, so wie die Linter das wollen, diese nochmal escapen würde, würde vermutlich regex nicht mehr gehen.TRex hat geschrieben:18.03.2022 20:24:26Das sind raw-Strings, und mit regex haben die nichts zu tun - sie sind dafür aber praktisch. Normalerweise müsstest du alle backslashes escapen (also sie zweimal schreiben), und mit raw string (korrekterweise raw string literals) musst du das nicht.
Und """...""" gibts auch noch.Meillo hat geschrieben:18.03.2022 22:07:55Bedeutet das, dass in Python r'...' und r"..." das Aequivalent zu Single Quotes in der Shell sind?
Normale '...' und "..." sind dann wohl austauschbar und entsprechen den Double Quotes in der Shell, vermute ich.
und das sagt, neben anderem:In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.
For triple-quoted strings, always use double quote characters to be consistent with the docstring convention in PEP 257.
(ka, obs da noch nen aktuelleres pep gibt, dass man kennen sollte, bin da grad nicht so auf dem Laufenden)For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""".
There are two forms of docstrings: one-liners and multi-line docstrings.
Code: Alles auswählen
[[id:0c664422c239][foo bar with linebreak
in second line]]
Code: Alles auswählen
['0c664422c239', 'foo bar with linebreak\nin second line']
Jetzt hab ich's wie ich das X reinbasteln muss.buhtz hat geschrieben:29.03.2022 12:12:35Das hier ist das ursprüngliche Pattern: \[\[id:(.+?)\]\[(.+?)\]\]
Code: Alles auswählen
\[\[id:(.+?)\]\[(.\X+?)\]\]
Das ist korrekt. Ich kenne mich mit Python nicht aus, aber `re.MULTILINE|re.DOTALL' als drittes Argument von `findall()' koennte die Loesung sein.buhtz hat geschrieben:29.03.2022 12:12:35Soweit ich verstehe arbeitet Regex per default nur Zeilenweise. Das lässt sich aber scheinbar ändern.
Code: Alles auswählen
[[https://foo.bar]]
<a href="https://foo.bar">https://foo.bar</a>
[[https://foo.bar][foobar]]
<a href="https://foo.bar">foobar</a>
Code: Alles auswählen
[[https://foo.bar]] and [[https://foo.bar][foobar]]
Code: Alles auswählen
https://foo.bar]] and [[https://foo.bar
foobar
Code: Alles auswählen
\[\[https\:\/\/([^\]\[]+)\]\[(.+?)\]\]
Code: Alles auswählen
\[\[https\:\/\/([^\]\[]+)\]\]