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

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Twitters not regex

I am getting Bummer! twitters does not seem to be a regex search agent'

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'(?P<email>[\w+.]+@[\w.]+),\s(?P<phone>\d{3}-\d{3}-\d{4})',string)
twitters = re.search(r'(?P<twitter>\s[\w\d]+)$',string,re.M)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Very close. You're missing the @-sign. Change the leading space to @:

# old version
twitters = re.search(r'(?P<twitter>\s[\w\d]+)$',string,re.M)

# new version
twitters = re.search(r'(?P<twitter>@[\w\d]+)$',string,re.M)
Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Well, thanks! That finally worked. I see now that I could use the space as a way to identify what part of the line I wanted, but then I have to realize that I am grabbing the space and including it with whatever I pulled out, not just using the space as a way to locate something. I thought the space was helpful because it identified the twitter address separate from an email address, which would not have a space. But simply identifying something as being at the end makes more sense. Thanks!