We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

vanne on 02/04/07


Tagged

regex rails ruby


Versions (?)


Sanitize String


Published in: Ruby 


Use this to sanitize a string and convert all wierd characters to your choice of delimiter

  1. #substitute string_name for your variable or a string
  2. #substitute "-" for your choice of character
  3. #note: doesn't recognize accented characters properly
  4. string_name.gsub(/[^a-z0-9]+/i, '-')

Report this snippet 

You need to login to post a comment.