[Python-de] Re: regex: Ausdruck matches wen auf einer Zeil e, fails when "freespacing"
"Peter J. Holzer" <[email protected]> Thu, 8 Dec 2022 12:29:01 +0100
| Newsgroups | gmane.comp.python.general.german |
|---|---|
| Organization | LUGA |
| Message-ID | <[email protected]> |
On 2022-12-08 07:20, robert rottermann <[email protected]> wrote: > Ich habe eine regular Expression um Sektionen in einem ini-File zu filtern. > > Dieser Ausdruck funktioniert wenn er auf eine Zeile geschrieben wird. Also: > > sp0 = '^\[[^\]\r\n]+](?:\r?\n(?:[^\[r\n].*)?)*' Auch eher nur zufällig. > Nicht aber wenn er "free spacing" geschrieben ist: > > sp2 = """ > ^\[[^\]\r\n]+] # match a section header > (?: # followed by the rest of the section > \r?\n # match a line break sequence > (?: # after Each line starts match > [^[\r\n] # Any character except "\[" or line break > .* # match rest of the line > )? # Group is optional to match empty lines > )* # Continue until end of section > """ Füge an dieser Stelle print(f"sp0=«{sp0}»") print(f"sp2=«{sp2}»") ein, dann siehst Du, wo der Fehler liegt. hp _______________________________________________ python-de Mailingliste -- [email protected] Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected] https://mail.python.org/mailman3/lists/python-de.python.org/ Mitgliedsadresse: [email protected]