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

pawkan kenluecha
pawkan kenluecha
26,303 Points

What is difference between ([+\w.]*@[+\w.]+),\s(?P<phone>\d{3}-\d{3}-\d{4}) and ([+\w.]*@[+\w.]+)|(?P<phone>\d{3}-\d{3 ?

In this exercise, I tried to write it this way.

([+\w.]*@[+\w.]+)|(?P<phone>\d{3}-\d{3}-\d{4})

I couldn't pass by this expression. I tried to check with the website that provides REG service and It worked really fine.

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: The difference appears to be in the separators.

Also, the second expression appears to be truncated. But assuming the missing parts match...

The first expression matches an email address separated from a phone number by a comma and a space. The phone number is also assigned to the group name "phone".

The second expression would match an email address OR a phone number, but not both. If the email address exists, the phone number would be overlooked and unassigned.