Skip to content

Instantly share code, notes, and snippets.

@superscott
Created December 12, 2012 17:59
Show Gist options
  • Save superscott/4270070 to your computer and use it in GitHub Desktop.
Save superscott/4270070 to your computer and use it in GitHub Desktop.
regex
def self.clean(value, level)
case level
when 1 #strip html and tags
results = Sanitize.clean(value)
when 2 #includes level 1, regex to allow symbols
leveltwo = Sanitize.clean(value)
leveltwo.strip!
results = leveltwo.gsub(/[^0-9a-zA-Z\(\)\|\:\/\,\'\.\-\@\_\[\]\&\?\=\s]/, "")
when 3 #includes level 1, regex to only allow alphanumeric
levelthree = Sanitize.clean(value)
levelthree.strip!
results = levelthree.gsub(/[^0-9a-zA-Z]/, "")
else
results = "well that didnt work"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment