๐ 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