Python - Regex error: 'NoneType' object has no attribute 'group'

Hi all,

Python newbie here.
I’m following allowing with the book ‘Automate the Boring Stuff with Python.’ I’m working through Chapter 7 where it introduces Regex and the .group method.

I’m writing the code straight from the book:

import re
phoneNumRegex = re.compile( r’((\ d\ d\ d)) (\ d\ d\ d-\ d\ d\ d\ d)’)
mo =‘My phone number is (415) 555-4242.’)

Yet I get the error: AttributeError: ‘NoneType’ object has no attribute ‘group’.

I’m not sure if I’m missing something or if the .group() method needs to be imported from another module?


I got some help from my MeetUp group, the spaces between the ‘\ d’ was causing the issue for anyone out there that is curious in the future.