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

Vidhya Sagar
Vidhya Sagar
1,568 Points

LOST.!Someone help

I get [] .

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'''
contacts=re.search(r'''
    ^(?P<email>[-\w\d.+]+@[-\w\d.]+),\t
    (?P<ph_no>\d{3}-\d{3}-\d{4})$

''',string,re.X|re.MULTILINE)

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

The only reason I can see is the use of the ^ character and the $ and the \t.

If you have a look at the RegEx Docs

The ^ says: Matches the start of the string, and in MULTILINE mode also matches immediately after each newline.

The $ says: Matches the end of the string or just before the newline at the end of the string, and in MULTILINE mode also matches before a newline

\t is a tab character, so be sure your string isnt using a normal space or use the \s which catches all types of whitespace characters.

string isnt starting with the email pattern, it starts with a Last Name and First Name then an email. So if you remove the ^ and $ it wont restrict email pattern to the start of the expression. :)

Hope that helps!