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

Cody Stephenson
Cody Stephenson
8,361 Points

Unhelp error message in email Reges task

I basically copied the email regex from the video before the task as below

But I'm getting the error message "Bummer: Didn't get the right output. Got ['kenneth@teamtreehouse.com,', 'andrew+gotcha@teamtreehouse.com,', 'exa.mple@example.co.uk,'], expected ['kenneth@teamtreehouse.com', 'andrew+gotcha@teamtreehouse.com', 'exa.mple@example.co.uk'].

Which kind of feels like "Task failed successfully"

import re

def find_emails(email_list):
    a = (re.findall(r'[-\w\d+.]+@[-\w\d.]+.', email_list))

# Example:
# >>> find_email("kenneth.love@teamtreehouse.com, @support, ryan@teamtreehouse.com, test+case@example.co.uk")
# ['kenneth@teamtreehouse.com', 'ryan@teamtreehouse.com', 'test@example.co.uk']

1 Answer

Steven Parker
Steven Parker
229,982 Points

You nearly have it! But if you take a close look at the output message:

     Got ['kenneth@teamtreehouse.com,' โ€ฆ
expected ['kenneth@teamtreehouse.com'  โ€ฆ

You can see that in the first case a comma was allowed as a part of the email address, contrary to challenge expectations.

This is because the very last thing in your regex string is a period, which acts as a wildcard and will match with anything. Perhaps that was just a typo, and if you remove it the regex will do exactly what the instructions asked for.

Cody Stephenson
Cody Stephenson
8,361 Points

Oh wow, good eye. Just another example of how and why regex drives people universally crazy.