Skip to content

Instantly share code, notes, and snippets.

@edwinlab
Created April 21, 2017 07:34
Show Gist options
  • Select an option

  • Save edwinlab/460878f2dad269a7ad8e4dce9524eb8d to your computer and use it in GitHub Desktop.

Select an option

Save edwinlab/460878f2dad269a7ad8e4dce9524eb8d to your computer and use it in GitHub Desktop.
def self.escape_characters_in_string(string)
pattern = /(\'|\"|\.|\*|\/|\-|\\|\)|\$|\+|\(|\^|\?|\!|\~|\`)/
string.gsub(pattern){|match|"\\" + match}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment