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!

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

Python Regex: Email Groups - Code Challenge

I'm at a loss on how to change this so it will satisfy the requirements of the challenge to pick out the twitter handles correctly.... From my understanding, its correct, but I suppose that's not the case!

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
                         ''',string, re.X|re.M)

twitters = re.search(r'''
                      ''',string, re.X|re.M)

1 Answer

William Li
William Li
Courses Plus Student 26,867 Points

Hi Trevor Currie , unlike part 1, this part of the challenge didn't ask you to group the pattern, so you don't have to do that, the only problem here is the ? before $ in your matching string, you shouldn't put it there. Get rid of that ? and you'll pass.

And you can simplify it a bit by removing some of the unnecessary stuffs from you RegEx.

twitters = re.search(r'''
                      ''',string, re.X|re.M)

Hope that helps.

Can't believe I missed it! Thanks William Li!

Welby Obeng
Welby Obeng
20,340 Points

how come you didnt put ^ before @?

I just didn't denote the beginning of the line. I think I was running into errors but I can't recall.