Skip to content

Gone with the Wind Solution


import re

bool(re.search(pattern='[a-z]\sg', string=quote))
# True

Explanation

  1. a-z matches any lowercase character
  2. [a-z]\s matches any lowercase character, followed by a whitespace character
  3. [a-z]\sg matches any lowercase character, followed by a whitespace character, followed by the letter g

re.search(pattern, string, ...) scans the string looking for the first location where the regular expression pattern produces a match. If it finds a match, it returns a match object, otherwise it returns None.

re.search(pattern='[a-z]\sg', string=quote)
# <re.Match object; span=(23, 26), match='t g'>

Casting the result of re.search() to a boolean indicates whether a match was found.

bool(re.search(pattern='[a-z]\sg', string=quote))
# True

Note

We'll learn more about match objects later.