|
8 | 8 | "\n", |
9 | 9 | "Up until now, to search in text we have used string methods find, startswith, endswith, etc. But sometimes you need more power.\n", |
10 | 10 | "\n", |
11 | | - "Regular expressions (regex) are their own little language that allows you to search through text and find matches with incredibly complex patterns. \n", |
| 11 | + "Regular expressions are their own little language that allows you to search through text and find matches with incredibly complex patterns. \n", |
12 | 12 | "\n", |
13 | 13 | "A regular expression, also referred to as \"regex\" or \"regexp\", provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters.\n", |
14 | 14 | "\n", |
15 | | - "To use regular you must import python's regex library `re`\n", |
| 15 | + "To use regular you need to import python's regex library `re`\n", |
16 | 16 | "https://docs.python.org/2/library/re.html" |
17 | 17 | ] |
18 | 18 | }, |
|
35 | 35 | }, |
36 | 36 | "outputs": [], |
37 | 37 | "source": [ |
38 | | - "# To run the examplse we are going to use some of the logs from the \n", |
| 38 | + "# To run the examples we are going to use some of the logs from the \n", |
39 | 39 | "# django project, a web framework for python\n", |
40 | 40 | "\n", |
41 | 41 | "django_logs = '''commit 722344ee59fb89ea2cd5b906d61b35f76579de4e\n", |
|
103 | 103 | "source": [ |
104 | 104 | "## Searching\n", |
105 | 105 | "\n", |
106 | | - "The most simple thing you can do with regexs in python is search through text to see if there is a match. To do this you use the methods `search` or `match`. `match` only checks if it matches at the beginning of the string and `search` check the whole string.\n", |
| 106 | + "The simplest thing you can do with regexs in python is search through text to see if there is a match. To do this you use the methods `search` or `match`. `match` only checks if it matches at the beginning of the string and `search` check the whole string.\n", |
107 | 107 | "\n", |
108 | 108 | " re.match(pattern, string) \n", |
109 | 109 | " re.search(pattern, string) " |
|
162 | 162 | "metadata": {}, |
163 | 163 | "source": [ |
164 | 164 | "### TRY IT\n", |
165 | | - "search for the word May in the django logs" |
| 165 | + "Search for the word May in the django logs" |
166 | 166 | ] |
167 | 167 | }, |
168 | 168 | { |
|
389 | 389 | "times = re.findall(time_pattern, django_logs)\n", |
390 | 390 | "print times\n", |
391 | 391 | "\n", |
| 392 | + "# Unpacking the tuple in the first line\n", |
392 | 393 | "for hours, mins in times:\n", |
393 | 394 | " print \"{} hr {} min\".format(hours, mins)" |
394 | 395 | ] |
|
444 | 445 | "\n", |
445 | 446 | "\n", |
446 | 447 | "0. Import re\n", |
447 | | - "1. Initailize a variable called paragraph to be an empty list and a variable called found_match to false.\n", |
| 448 | + "1. Initialize a variable called paragraph to be an empty list and a variable called found_match to false.\n", |
448 | 449 | "2. Create a list of patterns to match and store in variable called patterns\n", |
449 | 450 | "3. Read in test file 'evidence.txt'.\n", |
450 | 451 | "4. For line in evidence:\n", |
|
0 commit comments