Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Regular Expressions in Python Introduction to Regular Expressions Email Groups

Didn't get a regex object

I do not find the error. What's wrong?

emails.py
import re

string = '''Love, Kenneth, kenneth+challenge@teamtreehouse.com, 555-555-5555, @kennethlove
Chalkley, Andrew, andrew@teamtreehouse.co.uk, 555-555-5556, @chalkers
McFarland, Dave, dave.mcfarland@teamtreehouse.com, 555-555-5557, @davemcfarland
Kesten, Joy, joy@teamtreehouse.com, 555-555-5558, @joykesten'''

contacts = re.search(r'''
    ^[\w]+,\s[\w]+,\s(?P<email>[\w.+]+@[\w.]),\s
    (?P<phone>\d{3}-\d{3}-\d{4}),\s[@\w]+$
''', string, re.X|re.M)

2 Answers

Tate Price
PLUS
Tate Price
Courses Plus Student 9,987 Points

I hope this helps

contacts = re.search(r'''
    (?P<email>[-\w\d.+]+@[-\w\d.]+)
    ,\s
    (?P<phone>\d{3}-\d{3}-\d{4})
''', string, re.X|re.M)

The solution above (posted by Tate) allowed me to pass the Code Challenge. Hooray!

The point of confusion for me, is that I printed contacts. I can see it's a special return object; I just expected something of a more predictable data structure like we'd seen in the past. I'm curious why. (If you recommend I not concern myself about it then that's fine too) :)

# >>>  <_sre.SRE_Match object; span=(15, 64), match='kenneth+challenge@teamtreehouse.com, 555-555-5555>

I found the answer, from Tate again (Tate, thank you!)