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 Name Groups

Please help with this regex! (SOLVED)

"Bummer! Didn't get the right content in the groups." Why???

names.py
import re

string = 'Perotto, Pier Giorgio'

names = re.match(r"(\w+), (\w+)", string)

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Your pattern needs to catch the space in the first name.

?

Kourosh Raeen
Kourosh Raeen
23,733 Points

In the first name "Pier Giorgio", there is a space between "Pier" and "Giorgio" and your pattern is not catching that.

Where exactly should I put the space? I am not catching "Giorgio" in the first place.

Kourosh Raeen
Kourosh Raeen
23,733 Points

In the second group. Right now you have any number of letters in that group. Add to it so that it becomes any number of letters followed by a space followed by any number of letters.

Oh thank you so much!