Lesson 24 of 55
PythonRegular Expressions
20 minutes
Course progress44%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 24 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
The re module enables powerful pattern‑matching with regular expressions. Patterns are defined as raw strings (r'...') to avoid escaping backslashes.
import re
text = 'The price is $45.99.'
pattern = r'\d+\.\d{2}' # matches numbers like 45.99
match = re.search(pattern, text)
if match:
print('Found price:', match.group())
Common functions: re.search(), re.match(), re.findall(), re.sub().