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 trialsarvienn thevendran
734 PointsRegular 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
14,869 PointsInside 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
734 Pointssarvienn thevendran
734 Pointshey! it just appears that I'm not supposed to put in commas inside sets. thank you so much for your time!