This is arguably a tad bit prettier: title.downcase.gsub(/[^a-z ]/, '').gsub(/ /, '-')
Not sure if it's that much better... -----Original Message----- From: rubyonrails-talk@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ben Knight Sent: Thursday, October 02, 2008 10:52 AM To: rubyonrails-talk@googlegroups.com Subject: [Rails] Removing Non Alpha & Numeric Characters From String Hello. We have book titles as a column in our database, which I would like to use in our URLS for SEO purposes. Given that these are titles, they include characters other than alphabets and numbers (e.g. punctuation, blanks, foreign characters in some cases). What's the easiest way to do this? Here is some more information: Original string: On One Flower: Butterflies, Ticks and a Few More Icks What I would like to see: on-one-flower-butterflies-ticks-and-a-few-more-icks I'm currently doing something like this; is there a better way? title.squeeze.downcase.tr("(),? !':.[]", "-").gsub('--', '-') Thanks in advance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---