Sanitize String


/ Published in: Ruby
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.