Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Findall not finding anything

Tags:

python

regex

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?

like image 910
user84296 Avatar asked Jan 21 '26 13:01

user84296


1 Answers

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']
like image 81
mkrieger1 Avatar answered Jan 23 '26 03:01

mkrieger1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!