I am learning about Regex and am stuck with this code:
import re
resume = '''
(738) 383-5729
(373) 577-0492
(403) 443-2759
(375) 880-8576
(641) 576-2342
(951) 268-8744
'''
phoneRegex = re.compile(r'\d')
mo = phoneRegex.findall(resume)
print(mo.group())
When I try with search instead of findall, it works. But it can't find any match with findall.
What am I doing wrong?
findall() returns a simple list of strings matching the pattern.
It has no group() method, just omit that:
>>> print(mo)
['7', '3', '8', '3', '8', '3', '5', '7', '2', '9', '3', '7', '3', '5', '7',
'7', '0', '4', '9', '2', '4', '0', '3', '4', '4', '3', '2', '7', '5', '9',
'3', '7', '5', '8', '8', '0', '8', '5', '7', '6', '6', '4', '1', '5', '7',
'6', '2', '3', '4', '2', '9', '5', '1', '2', '6', '8', '8', '7', '4', '4']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With