Posted By

vanne on 02/04/07


regex rails ruby

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


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.