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

hugo dahl
hugo dahl
2,967 Points

whats wrong

help

names.py
import re

string = 'Perotto, Pier Giorgio'

# Create variable names with re.match()
names_pattern = r'(\w+), (\w+)'
names_match = re.match(names_pattern, string)
names = names_match.groups() if names_match else None

# Example usage:
print("Names:", names)

1 Answer

Steven Parker
Steven Parker
231,236 Points

The pattern needs to account for the space as part of the first name.

Also, the result from the re.match itself should be assigned to "names". The challenge is expecting to be able to use .groups() on it while checking the solution.