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
80 changes: 80 additions & 0 deletions 6.3_using_RE_after_first_QM
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "16bfecfd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n"
]
}
],
"source": [
"# Re wood: Search for the word wood in the song_text supplied, and enriched by wannabe-developer \n",
"\n",
"import re\n",
"song_text_enriched = \"\"\"\"How much wood would a woodchuck chuck\\n\",\n",
" \"If a woodchuck could chuck wood?\\n\",\n",
" \"He would chuck, he would, as much as he could,\\n\",\n",
" \"And chuck as much as a woodchuck would\\n\",\n",
" \"If a Mrs. Smith or Mr. Smith, could chuck wood\\\\n\\\\r\\\\t.\\\"\\\"\\\"\\n\",\n",
" \"\\n\",\"\"\"\n",
"\n",
"# Remark: To find all appearances of the word wood in the song_text_supplied please use:\n",
"# search_result_wood = re.finditer(r'\\ wood', song_text_enriched)\n",
"\n",
"# Remark: To find the word \"wood\", in case no alphabetical character follows, please use:\n",
"\n",
"search_result_wood = re.finditer(r'\\ wood[^a-zA-Z]', song_text_enriched)\n",
"count_wood = 0\n",
"for occurence_of_wood in search_result_wood:\n",
" count_wood += 1\n",
" print(count_wood)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83b2670e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "498b4543",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}