Courses/Regex & Text Processing

๐Ÿ” Regex & Text Processing

Capture Groups

Extract pieces with parentheses and named groups.

Parentheses create capture groups. Name them with (?P<name>...) for clarity.

import re
m = re.match(r"(?P<user>\w+)@(?P<host>[\w.]+)", "ada@example.com")
print(m.group("user"))  # ada
print(m.group("host"))  # example.com
main.py
Output
Press Run to execute.
Expected output
2024 06 15

Sign in to track your progress across lessons.