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

Didn't get enough grous

I don't understand the problem. When running in colab it seems to work. I do have 2 groups it tells me not enough groups

names.py
import re

string = 'Perotto, Pier Giorgio'
pattern = r'[\w]+,\s[\w\s]+'
names = re.match(pattern, string)

1 Answer

Steven Parker
Steven Parker
231,248 Points

I think you may be confusing character class with group. The code above has an appropriate pattern which contains two character classes, but it has no groups.

Groups identify portions of a match and are defined in a regex with parentheses.