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 trialY B
14,136 PointsRegex email groups.
The individual parts work, but not sure how to combine them? A \t in between the two groups doesn't work either?
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.]+)(?P<phone>[\d-]+)', string)
5 Answers
Kenneth Love
Treehouse Guest TeacherWell, the string has a comma and a space between them. Try that? :D
Y B
14,136 PointsAh I always seem to fail at the silly bits.
Thanks.
David B Dinkins
71,472 PointsI'm having a similar sort of issue. I think I've added the \s,
characters in close to the right place because I am getting some content in my regex search object.
But the error shows that I'm only getting the first entries, Email: "kenneth+challenge@teamtreehouse.com,", Phone: "555-555-5555". Here's my code:
contacts = re.search(r'''(?P<email>[-\w\d+.]+@[-\w\d.\s,]+)(?P<phone>\d{3}-\d{3}-\d{4})''', string)
Kenneth Love
Treehouse Guest TeacherLooks like you're catching the comma and space in the email
group. You shouldn't, that's messy data and not part of a valid email address. The comma and space are meant as separators between the two bits of data.
Mike Smith
11,863 PointsI'm still stumped!!
This code:
<p>contacts = re.search(r'(?P<email>[-\w\d+.]+@[-\w\d.]+)([,\s]+)(?P<phone>\d{3}-\d{3}-\d{4})', string, re.X|re.M)</p>
results in :
<p> contacts.groupdict() = {'email': 'kenneth+challenge@teamtreehouse.com', 'phone': '555-555-5555'}</p>
What am I missing?
David B Dinkins
71,472 PointsYou've got to remove any html tags. I'd also check your ([,\s]+)
between the groups. It's looking for more than you need it to.
David B Dinkins
71,472 PointsAlright, I moved the comma and the space around and it worked. Thanks!
I finally got the second task completed, too--I was over thinking it.