Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
fahad lashari6,771 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,029 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.