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 trialChris Massie
6,233 PointsSo for the Extra Credit for the Strings badge, I don't recall learning the method for removing punctuation.
I browsed google for said method, and ended up finding a nifty code bit to create this method, but not the actual method. Did I miss something in the videos?
2 Answers
Hugo Paz
15,622 PointsThere isn't a method to remove punctuation. You need to use gsub with a regexp. Try string.reverse.gsub(/[^\w\s\d]/, '')
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsMaybe my solution was a bit more hackey, but I don't know regular expressions so I used the tr() method like this:
string.tr('`~!@#$%^&*()-=_+[]{}|\:";\'<>?,./', '')
Chris Massie
6,233 PointsChris Massie
6,233 PointsThat works. Just was not expecting the Extra Credit to involve foreign code(foreign to me, at least). I'll know to consider all options for next time. Thanks!