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

Taylor Schimek
Taylor Schimek
19,318 Points

Trouble with Regex code challenge

Challenge accepts solution to task 1. Then, when checking task 2 it returns: Oops! It looks like take 1 is no longer passing. I didn't change anything from the task 1 section.
Any ideas?

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
'''
# task 1
contacts = re.search(r'''
    (?P<email>[-\w\d.+]+@[-\w\d.]+)  #email
    ,\s+
    (?P<phone>\d{3}-\d{3}-\d{4})  #phone
''', string, re.X)

# task 2
twitters = re.search(r'(\s@[\w\d]+)$', string, re.X|re.M)

2 Answers

You are so close. You do not need to check for the space before the twitter handle.

twitters = re.search(r'(@[\w\d]+)$', string, re.M)
Taylor Schimek
Taylor Schimek
19,318 Points

Still getting that task 1 is no longer passing. Can't see how i'm affecting the Task 1 code?? Thanks, though, for catching that space before the Twitter handle.

Try removing re.X as you are not needing VERBOSE

Taylor Quinn
Taylor Quinn
20,003 Points

Why do we only mark the end of the string and not the beginning?

Taylor Schimek
Taylor Schimek
19,318 Points

Still got the same Oops! Looks like task1 is no longer passing.