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 Players Dictionary and Class

vincent schouten
vincent schouten
9,687 Points

getting incomplete score with challenge players.py

I wrote the code for this challenge but it returns the score incompletely; instead of '20', it returns '2'. Can somebody help me out? Thanks

players = re.search(r''' (?P<last_name>[\w]+) ,\s (?P<first_name>[\w]+) :\s (?P<score>[\d{2}]) ''', string, re.X|re.M)

print(players.group()) ## gives "Love, Kenneth: 2" (instead of 20)

2 Answers

Dan Johnson
Dan Johnson
40,533 Points

You'll want to drop the square brackets around the score capturing group, since you're not looking for any different types to match, just a specific number of digits.

Don't forget to add names to your groups so you can extract the values, and to capture spaces in names for the last item.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You said the groups were named, ?P but then didn't name them.