Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Email

sarvienn thevendran
sarvienn thevendran
734 Points

Regular Expressions

Hey, I've been assigned to find certain emails from a string. Which part of my code is causing the error?

import re

# 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']

def find_emails(string):
    cr7 = re.findall(r'\b[\w,\d,.,+]+\b@[\d,.]+,[\w,.]+',string)
    return cr7

1 Answer

Eric Cahanin
Eric Cahanin
14,868 Points

Inside the brackets, the . that normally matches everything matches only a literal '.' So after your @, you're requiring one or more digits or .'s. Try to simplify your regex so that it's easier to understand. For example, \w already matches digits, so you don't need to include \d inside the brackets. Something like https://regex101.com/ can help you get a feel for how things match.

sarvienn thevendran
sarvienn thevendran
734 Points

hey! it just appears that I'm not supposed to put in commas inside sets. thank you so much for your time!