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: %% Cell type:markdown id: tags:
# 12. Übungsblatt # 12. Übungsblatt
Mit diesem Python-Code können Sie Ihren regulären Ausdruck testen: Mit diesem Python-Code können Sie Ihren regulären Ausdruck testen:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
import re import re
""" """
Ändern Sie den folgenden regulären Ausdruck, so dass alle Ändern Sie den folgenden regulären Ausdruck, so dass alle
positiven Muster erkannt werden, aber kein negatives Muster. positiven Muster erkannt werden, aber kein negatives Muster.
""" """
muster = re.compile("ap.*t") muster = re.compile(" ")
positive = [ positive = [
"rap them", "rap them",
"tapeth", "tapeth",
"apth", "apth",
"wrap/try", "wrap/try",
"sap tray", "sap tray",
"87ap9th", "87ap9th",
"apothecary" "apothecary"
] ]
negative = [ negative = [
"aleht", "aleht",
"happy them", "happy them",
"tarpth", "tarpth",
"Apt", "Apt",
"peth", "peth",
"tarreth", "tarreth",
"ddapdg", "ddapdg",
"apples", "apples",
"shape the" "shape the"
] ]
# testen, ob alle positiven Muster richtig erkannt werden # testen, ob alle positiven Muster richtig erkannt werden
positive_not_matched = [s for s in positive if not muster.findall(s)] positive_not_matched = [s for s in positive if not muster.findall(s)]
if positive_not_matched: if positive_not_matched:
print("Folgende positive Muster wurden nicht erkannt:", ", ".join(positive_not_matched)) print("Folgende positive Muster wurden nicht erkannt:", ", ".join(positive_not_matched))
# testen, ob keine negativen Muster erkannt werden # testen, ob keine negativen Muster erkannt werden
negative_matched = [s for s in negative if muster.findall(s)] negative_matched = [s for s in negative if muster.findall(s)]
if negative_matched: if negative_matched:
print("Folgende negativen Muster wurden erkannt:", ", ".join(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