Regular Expressions
Python · Intermediate
Definition
The re module matches text patterns such as emails, numbers and dates.
Powerful for validation and extraction.
Diagram
Flowchart
Example: Extract numbers
import re
print(re.findall(r'\d+', 'Order 12 has 3 items'))Output: ['12', '3']
Key points
- Use raw strings r'...'
- Avoid regex for full HTML parsing
Interview questions
match vs search?
match checks only the start; search scans the whole string.