Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix e-mail regular expression #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 14-Strings-and-Regular-Expressions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1863,15 +1863,15 @@
}
],
"source": [
"email2 = re.compile(r'[\\w.]+@\\w+\\.[a-z]{3}')\n",
"email2 = re.compile(r'[\\w\\.]+@\\w+\\.[a-z]{3}')\n",
"email2.findall('barack.obama@whitehouse.gov')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We have changed ``\"\\w+\"`` to ``\"[\\w.]+\"``, so we will match any alphanumeric character *or* a period.\n",
"We have changed ``\"\\w+\"`` to ``\"[\\w\\.]+\"``, so we will match any alphanumeric character *or* a period.\n",
"With this more flexible expression, we can match a wider range of email addresses (though still not all – can you identify other shortcomings of this expression?)."
]
},
Expand All @@ -1892,7 +1892,7 @@
},
"outputs": [],
"source": [
"email3 = re.compile(r'([\\w.]+)@(\\w+)\\.([a-z]{3})')"
"email3 = re.compile(r'([\\w\\.]+)@(\\w+)\\.([a-z]{3})')"
]
},
{
Expand Down Expand Up @@ -1946,7 +1946,7 @@
}
],
"source": [
"email4 = re.compile(r'(?P<user>[\\w.]+)@(?P<domain>\\w+)\\.(?P<suffix>[a-z]{3})')\n",
"email4 = re.compile(r'(?P<user>[\\w\\.]+)@(?P<domain>\\w+)\\.(?P<suffix>[a-z]{3})')\n",
"match = email4.match('guido@python.org')\n",
"match.groupdict()"
]
Expand Down