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!
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
fahad lashari7,693 Points
For anyone who is stuck on the next code challenge.
import re string = 'Perotto, Pier Giorgio' names = re.match(r'''([-\w]+),\s([\w ]+[\w]+)''', string, re.I)
This is what you need to do. Most people are forgetting to use the re.I function. And also for the first names, it's simpler and easier to just put the space explicitly after the first name.
Hope this helps. Study as to why it passes the challenge. Re-do the challenge yourself a few times without looking at this. To really re-enforce the knowledge.
Chris FreemanTreehouse Moderator 68,404 Points
Always look for opportunities to simplify regexs. The first name group can be simplified:
[\w ]+[\w]+ # "one or more of word chars # and spaces, followed by one # or more word chars" reduces to [\w ]+ # one or more of word chars and spaces
names = re.match(r'([\w]+),\s([\w\s]+)', string)
I used this code and it was accepted. I guess the
re.I isn't necessary.