DEV Community

Discussion on: Advent of Code 2020: Day 02(b) using regex named groups

Collapse
 
spark706 profile image
spark706

I'm not sure where the & is introduced. I even tried your code copy and pasted into the IDE. But what I did notice and change to get the code working is used re.match instead of re.compile. Not sure why, still early in learning Python, but the following worked:

pattern = re.match('(?P\d+)-(?P\d+) (?P\w): (?P\w+)', entry)
print(pattern.groupdict())

Thanks for the help and this series. Even on Day 2 and it's been extremely helpful.