neg. Lookbehind funktioniert nicht

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
toby

hallo!
warum tut dieser code nicht, was er soll.
da im str kein boese, sondern nur boehse vorkommt, ist es verwunderlich, dass gar kein match vorhanden ist.

Code: Alles auswählen

import re,string
regexp="(<?!boese) (.*?) im"
str="der boehse mann im mond"
treffer=re.compile(regexp,re.I|re.M)
matches=treffer.findall(str)
print matches
wie muss der regexp stattdessen heißen?
danke

Edit (Leonidas): Code in Python-Tags gesetzt.
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Versuchs mal mit

Code: Alles auswählen

reg_exp_code = r'(?<=%s).*?(?=%s)' % (start, stop)
Darin ist sowohl Lookahead als auch negativer Lookahead.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
joe

Leonidas hat geschrieben:Darin ist sowohl Lookahead als auch negativer Lookahead.
Nein. Das ist ein lookbehind und ein lookahead und beide sind positiv.
joe
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Ups, sorry. Dann werf ich mal das passende Kapitel aus dem Regex-HOWTO in die Runde.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Antworten