ich suche ein Regex Patten. Ich habe einen Text(Alice im Wunderland) und suche folgenden Satz(Unterstriche stehen für Wörter): das _ mir _ _ _ vor.
Hat Jemand eine Idee für ein Pattern?

Code: Alles auswählen
#!/usr/bin/env python3
from pathlib import Path
from pyparsing import CaselessLiteral, Regex, lineno
def main():
text = Path("Downloads", "pg19778.txt").read_text("utf-8")
word = Regex(r"\w+")
das, mir, vor = map(CaselessLiteral, ["das", "mir", "vor"])
needle = das + word + mir + word * 3 + vor
for _, start, end in needle.scan_string(text, overlap=True):
print(f"Zeile {lineno(start, text)}: {text[start:end]}")
if __name__ == "__main__":
main()
Code: Alles auswählen
Zeile 483: Das kommt mir gar nicht richtig vor