Here's a quote from Gone with the Wind 👫
Check if it contains
- a lowercase letter
- followed by a single space
- followed by the letter g
Expected result
Should return True
.
Regex Functions
Regex Patterns
Solution¶
Explanation
a-z
matches any lowercase character[a-z]\s
matches any lowercase character, followed by a whitespace character[a-z]\sg
matches any lowercase character, followed by a whitespace character, followed by the letter g
[re.search(pattern, string, ...)
][re-search] 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
.
Casting the result of re.search()
to a boolean indicates whether a match was found.