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

Mohsen Qaddoura
Mohsen Qaddoura
22,237 Points

Answer to challenge not getting any output

here's my code

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'''
    ^(?P<email>[-\w\d.+]+@[-\w\d.]+)\t # Email
    (?P<Phone>d{3}-\d{3}-\d{4})\t$''', string, re.X|re.M)
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'''
Mohsen Qaddoura
Mohsen Qaddoura
22,237 Points

I still did not pass this challenge, and the word length one which I'll post in a separate question, though I went successfully though all the rest of the course.

Here is my modified code as per your kind answer:

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'''
    (?P<email>[-\w\d.+]+@[-\w\d.,]+\s) # Email
    (?P<phone>\d{3}-\d{3}-\d{4},\s)''', string, re.X|re.M)

Now I'm getting this error message:

Bummer! Didn't get the right content in your groups. Email: "kenneth+challenge@teamtreehouse.com, ", Phone: "555-555-5555, ".

I'm assuming it's the trailing comma at the end of each group content or just the phone group causing this error, I have tried many various modification to my code but none of the ones that gave a regex search object got rid of the trailing comma. I'm not sure what else could be the required groups content.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Don't include the comma or the space. They're not part of the email address or the phone number.

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

There aren't any tab characters in the code challenge, so you'll want to catch \s instead.

Mohsen Qaddoura
Mohsen Qaddoura
22,237 Points

I've completed the course. Thank you .

For some reason I could not mark or comment on your latest answer as they both became unavailable after I removed an initial comment!

Waiting for more exciting Python courses :)