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 trialSimon Wei
1,474 PointsDidn't get the right groups from your regex
Hi Kenneth,
I went through the questions & answers in the forum, but didn't find anyone else having the same issue.
I ran this on my local IDE (Spyder) which produced the following results when print contacts, contacts.group(), contacts.groupdict() using the code:
contacts = <_sre.SRE_Match object; span=(15, 64), match='kenneth+challenge@teamtreehouse.com, 555-555-5555> contacts.group() = kenneth+challenge@teamtreehouse.com, 555-555-5555 contacts.groupdict() = {'email': 'kenneth+challenge@teamtreehouse.com', 'phone': '555-555-5555'}
because there is no example of the correct answer, I'm not sure what I missed.
It'd be great if you could help.
Many thanks,
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
(?P<phone>(\d{3}\-\d{3}-\d{4}))
''', string, re.X| re.I)
Andy Davis
19,682 PointsAndy Davis
19,682 PointsI believe your issue is that you need to pass the re.M (Multiline) flag instead of the re.I (Ignore Case) flag. Since you're not matching any specific character cases in the regex, you don't need the Ignore Case flag.