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 trialJeremy Bradrick
6,731 PointsPython Email Groups "Didn't get a regex search object."
I've tried everything I can think of. I've looked through several other forum posts and compared my solution. I don't understand why it won't take it.
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.+]+@[-\s\d.]+),\s
(?P<phone>\(?\d{3}\)?-?\s?\d{3}-\d{4})
''', string, re.X|re.M)
2 Answers
Chase Marchione
155,055 PointsHi Jeremy,
If you turn that first 's' for the e-mail pattern into a 'w', you should be able to pass the task.
From the Python documentation (https://docs.python.org/2/library/re.html):
"\w When the LOCALE and UNICODE flags are not specified, matches any alphanumeric character and the underscore; this is equivalent to the set [a-zA-Z0-9_]. With LOCALE, it will match the set [0-9_] plus whatever characters are defined as alphanumeric for the current locale. If UNICODE is set, this will match the characters [0-9_] plus whatever is classified as alphanumeric in the Unicode character properties database."
"\s When the UNICODE flag is not specified, it matches any whitespace character, this is equivalent to the set [ \t\n\r\f\v]. The LOCALE flag has no extra effect on matching of the space. If UNICODE is set, this will match the characters [ \t\n\r\f\v] plus whatever is classified as space in the Unicode character properties database."
(?P<email>[-\w\d.+]+@[-\w\d.]+),\s
Hope this helps!
Jeremy Bradrick
6,731 PointsThat worked. I had just copied the example email search string that was given in the corresponding video from my notes.