Jan-01-2022, 03:46 PM
Hi,
My code for finding a certain text in a larger text doesn't work. It should give: " Phone number found: 415-555-4242". What am i doing wrong?
My code for finding a certain text in a larger text doesn't work. It should give: " Phone number found: 415-555-4242". What am i doing wrong?
import re phoneNumRegex=re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') phoneNumRegex=re.compile(r'\d\d\d-\d\d-\d\d\d\d') mo=phoneNumRegex.search('My number is 415-555-4242.') print('Phone number found: ' + mo.group()) Traceback (most recent call last): File "<pyshell#35>", line 1, in <module> print('Phone number found: ' + mo.group()) AttributeError: 'NoneType' object has no attribute 'group'