Reguläre Ausdrücke in Python (Reguläre Ausdrücke in Python), lesson, page 724608
https://www.purl.org/stefan_ram/pub/regulaere_ausdruecke_python (permalink) is the canonical URI of this page.
Stefan Ram
Python-Kurs

Textsuchen in Python 

main.py

korpus = '''
In Dänemark liegt ein altes Schloß, das heißt Kronburg.
Ich möchte vom Nachtwächter unseres Dorfes erzählen.
5. De Buren bi Regenweder
Dann ging der Perpendikel tick, tack!
Die Uhr sagte: "Tick! tack!" und die Zeiger drehten sich.
'''

predicate = lambda line: "tack" in line

result = filter( predicate, korpus.split( "\n" ) )

print( "\n".join( result ))

transcript
Dann ging der Perpendikel tick, tack!
Die Uhr sagte: "Tick! tack!" und die Zeiger drehten sich.
main.py

import re

korpus = '''
In Dänemark liegt ein altes Schloß, das heißt Kronburg.
Ich möchte vom Nachtwächter unseres Dorfes erzählen.
5. De Buren bi Regenweder
Dann ging der Perpendikel tick, tack!
Die Uhr sagte: "Tick! tack!" und die Zeiger drehten sich.
'''

predicate = lambda line: re.search( "tack", line )

result = filter( predicate, korpus.split( "\n" ) )

print( "\n".join( result ))

transcript
Dann ging der Perpendikel tick, tack!
Die Uhr sagte: "Tick! tack!" und die Zeiger drehten sich.

 

About this page, Impressum  |   Form for messages to the publisher regarding this page  |   "ram@zedat.fu-berlin.de" (without the quotation marks) is the email address of Stefan Ram.   |   A link to the start page of Stefan Ram appears at the top of this page behind the text "Stefan Ram".)  |   Copyright 1998-2020 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram. relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram724608 stefan_ram:724608 Reguläre Ausdrücke in Python Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd724608, slrprddef724608, PbclevtugFgrsnaEnz Explanation, description, info, information, note,

Copyright 1998-2020 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram.
https://www.purl.org/stefan_ram/pub/regulaere_ausdruecke_python