Skip to content
Snippets Groups Projects
Commit 1e5c3d3f authored by Prof. Dr. Robert Jäschke's avatar Prof. Dr. Robert Jäschke
Browse files

Beispiel-Muster vereinfacht

parent c3311f51
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# 12. Übungsblatt
Mit diesem Python-Code können Sie Ihren regulären Ausdruck testen:
%% Cell type:code id: tags:
```
import re
"""
Ändern Sie den folgenden regulären Ausdruck, so dass alle
positiven Muster erkannt werden, aber kein negatives Muster.
"""
muster = re.compile("ap.*t")
muster = re.compile(" ")
positive = [
"rap them",
"tapeth",
"apth",
"wrap/try",
"sap tray",
"87ap9th",
"apothecary"
]
negative = [
"aleht",
"happy them",
"tarpth",
"Apt",
"peth",
"tarreth",
"ddapdg",
"apples",
"shape the"
]
# testen, ob alle positiven Muster richtig erkannt werden
positive_not_matched = [s for s in positive if not muster.findall(s)]
if positive_not_matched:
print("Folgende positive Muster wurden nicht erkannt:", ", ".join(positive_not_matched))
# testen, ob keine negativen Muster erkannt werden
negative_matched = [s for s in negative if muster.findall(s)]
if negative_matched:
print("Folgende negativen Muster wurden erkannt:", ", ".join(negative_matched))
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment