Skip to content

Commit 64a5077

Browse files
committed
fix escaping in jupyter notebook
also added some more comments above the change in word match regex of last 2 commits
1 parent e14041f commit 64a5077

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

days/28-30-regex/regex.ipynb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,11 @@
247247
"cell_type": "markdown",
248248
"metadata": {},
249249
"source": [
250-
"Of course you can do the same with `words.split()` but if you have more requirements you might fit it in the same regex, for example let's only count words that start with a capital letter. I am using the _`[]` character class_ as an alternative to \\w here: "
250+
"Of course you can do the same with `words.split()` but if you have more requirements you might fit it in the same regex, for example let's only count words that start with a capital letter.\n",
251+
"\n",
252+
"I am using two _character classes_ here (= pattern inside `[]`), the first to match a capital letter, the second to match 0 or more common word characters. \n",
253+
"\n",
254+
"Note I am escaping the single quote (') inside the second character class, because the regex pattern is wrapped inside single quotes as well: "
251255
]
252256
},
253257
{
@@ -258,7 +262,7 @@
258262
"source": [
259263
"from collections import Counter\n",
260264
"\n",
261-
"cnt = Counter(re.findall(r"[A-Z][A-Za-z0-9']*", text))\n",
265+
"cnt = Counter(re.findall(r'[A-Z][A-Za-z0-9\\']*', text))\n",
262266
"cnt.most_common(5)"
263267
]
264268
},
@@ -471,7 +475,7 @@
471475
"name": "python",
472476
"nbconvert_exporter": "python",
473477
"pygments_lexer": "ipython3",
474-
"version": "3.6.1"
478+
"version": "3.6.5"
475479
}
476480
},
477481
"nbformat": 4,

0 commit comments

Comments
 (0)