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

Chih-Wei Hsu
Chih-Wei Hsu
11,132 Points

players challenge

i can't figure out the solution to task 1 of the challenge. please help.

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

1 Answer

Dario Tordoni
Dario Tordoni
9,635 Points

Hi Chih-Wei Hsu, if you use:

?P

for creating groups, you also have to add the name of the group:

(?P < name_here > your_code_here)

Be also careful because not all the players have a single-word last-name and single-word first-name. Consider spacing between them. Colons or commas should be outside groups.

If I'm not in wrong \t is for tabs, but there are not tabs in the string; using \s instead should be the right way to handle your string. Try again editing your code

For further information, here is the official re documentation