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
Christopher Gunawan
10,754 PointsQuestion about ",\s"
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]+@[.\w]+) #email ,\s (?P<phone>\d{3}-\d{3}-\d{4}) #phone ''', string, re.X|re.M)
Here is my answer. It is correct, but my question is why do I need to add the ",\s" if I do not want to capture it?
1 Answer
Daniel Santos
34,969 PointsHey Christopher,
If you think about it, you do want to match, you just don't care about the value. And you a point, really don't care about the spaces, but you want to make sure there are there.
For example, if I want to match a full name string in this pattern "<first_name><space><last_name>", I do want to make sure (match) that a space character is there, between the first and last name that is. That's the reason for the \s.
Make sense? Follow up otherwise :)
-Dan
Christopher Gunawan
10,754 PointsChristopher Gunawan
10,754 PointsThanks!