Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Groups

benjamin siverly
benjamin siverly
3,430 Points

Any reason why my address_book capture is returning an empty list?

print(re.findall(r'''
    ([-\w ]+,\s[-\w]+)\t           # name
    ([-\w\d.+]+@[-\w\d.]+)\t       # email
    (\(\d[3]\)?-?\s?d{3}-\d{4})\t  # phone
    ([\w\s]+,\s[\w\s]+)            # job / company
    (@[\w\d]+)                     # twitter
''', data, re.X))
Cheo R
Cheo R
37,150 Points

What doest your data look like?

2 Answers

Hi. You have two main errors that I can see.

phone line: {3} instead of [3] and no ? in at the beginning.

job company line: you have no \t at the end of the line.

the below script should work for you.

print(re.findall(r''' ([-\w ]+,\s[-\w ]+)\t # last and first names. ([-\w\d.+]+@[-\w\d.]+)\t # Email ((?\d{3})?-?\s?\d{3}-\d{4})\t # Phone number ([\w\s]+,\s[\w\s]+)\t # Job company (@[\w\d]+) # TwitterHandle ''', data, re.X))

Ross Coe
Ross Coe
5,061 Points

^ need to watch out =your parens are not escaped !!