421421
422422While this worked, it actually results in pretty brittle code that is
423423assuming the lines are nicely formatted. If you were to add enough error
424- checking (or a big try/except block) to insure that your program never
424+ checking (or a big try/except block) to ensure that your program never
425425failed when presented with incorrectly formatted lines, the code would
426426balloon to 10-15 lines of code that was pretty hard to read.
427427
@@ -465,10 +465,11 @@ When the program runs, it produces the following output:
465465Escape character
466466----------------
467467
468- Since we use special characters in regular expressions to match the
469- beginning or end of a line or specify wild cards, we need a way to
470- indicate that these characters are "normal" and we want to match the
471- actual character such as a dollar sign or caret.
468+ Regular expressions utilize special characters like ` ^ ` to match the
469+ beginning of a line, ` $ ` for the end of a line, and ` . ` as a wildcard;
470+ however, sometimes we want to match those characters literally. We
471+ need a way to indicate that we want to match the actual character such
472+ as a caret symbol, dollar sign, or period.
472473
473474We can indicate that we want to simply match a character by prefixing
474475that character with a backslash. For example, we can find money amounts
@@ -483,7 +484,7 @@ y = re.findall('\$[0-9.]+',x)
483484Since we prefix the dollar sign with a backslash, it actually matches
484485the dollar sign in the input string instead of matching the "end of
485486line", and the rest of the regular expression matches one or more digits
486- or the period character. * Note: * Inside square brackets,
487+ or the period character. Remember, as we saw above, inside square brackets,
487488characters are not "special". So when we say ` [0-9.] ` , it really means
488489digits or a period. Outside of square brackets, a period is the
489490"wild-card" character and matches any character. Inside square brackets,
0 commit comments