A capturing group is a parenthesized part of a regular-expression pattern whose matched text can be retrieved separately. Group 0 is the full match; numbered groups correspond to the parenthesized parts. section 2.4.4
match = re.match(r"(\w+), (\w+)", "Homework, urgent; today")
print(match)
# output: <re.Match object; span=(0, 16), match='Homework, urgent'>
match.groups()
# output: ('Homework', 'urgent')
match.group(0)
# output: 'Homework, urgent'
match.group(1)
# output: 'Homework'
match.group(2)
# output: 'urgent'
This example separates “Homework” and “urgent” from the full match using numbered groups. section 2.4.4
Groups can capture separate fields, such as an ID, title, and description, for later processing. Numbering many groups can be error-prone; named groups make the captured data clearer and easier to refer to. section 2.5.2 section 2.5.4





