Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Seminar Problemorientierte Programmierung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Jensen
Seminar Problemorientierte Programmierung
Commits
46622aa6
Commit
46622aa6
authored
6 years ago
by
Michel Schwab
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of scm.cms.hu-berlin.de:ibi/python
parents
572f2f08
1e5c3d3f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/uebung_regex.ipynb
+67
-0
67 additions, 0 deletions
notebooks/uebung_regex.ipynb
with
67 additions
and
0 deletions
notebooks/uebung_regex.ipynb
0 → 100644
+
67
−
0
View file @
46622aa6
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 12. Übungsblatt\n",
"\n",
"Mit diesem Python-Code können Sie Ihren regulären Ausdruck testen:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"\n",
"\"\"\"\n",
"Ändern Sie den folgenden regulären Ausdruck, so dass alle \n",
"positiven Muster erkannt werden, aber kein negatives Muster.\n",
"\"\"\"\n",
"muster = re.compile(\" \") \n",
"positive = [\n",
" \"rap them\",\n",
" \"tapeth\",\n",
" \"apth\",\n",
" \"wrap/try\",\n",
" \"sap tray\",\n",
" \"87ap9th\",\n",
" \"apothecary\"\n",
"]\n",
"\n",
"negative = [\n",
" \"aleht\",\n",
" \"happy them\",\n",
" \"tarpth\",\n",
" \"Apt\",\n",
" \"peth\",\n",
" \"tarreth\",\n",
" \"ddapdg\",\n",
" \"apples\",\n",
" \"shape the\"\n",
"]\n",
"\n",
"# testen, ob alle positiven Muster richtig erkannt werden\n",
"positive_not_matched = [s for s in positive if not muster.findall(s)]\n",
"if positive_not_matched:\n",
" print(\"Folgende positive Muster wurden nicht erkannt:\", \", \".join(positive_not_matched))\n",
"\n",
"# testen, ob keine negativen Muster erkannt werden\n",
"negative_matched = [s for s in negative if muster.findall(s)]\n",
"if negative_matched:\n",
" print(\"Folgende negativen Muster wurden erkannt:\", \", \".join(negative_matched))\n"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% 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(" ")
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))
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment