Created
June 7, 2012 23:43
-
-
Save crazymykl/2892439 to your computer and use it in GitHub Desktop.
A quickie to escape metacharacters in strings for use in jQuery selectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jqe(str) | |
str.gsub( /[!"\#$%&'()*+,.\/:\\;<=>?@\[\]^`{|}~]/, '\\\\\\\\\&') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to make this nil-safe, call .to_s on str first.