Skip to content
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('[email protected]')"
]
},
{
"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('[email protected]')\n",
"match.groupdict()"
]
Expand Down