Open this example in the interactive library
Source code
import re
match = re.fullmatch(r'(?P<year>\d{4})-(?P<month>\d{2})', '2026-10')
print(match.groupdict())Sample output
{'year': '2026', 'month': '10'}
Open this example in the interactive library
import re
match = re.fullmatch(r'(?P<year>\d{4})-(?P<month>\d{2})', '2026-10')
print(match.groupdict()){'year': '2026', 'month': '10'}