Created
May 9, 2012 03:37
-
-
Save paganotoni/2641622 to your computer and use it in GitHub Desktop.
Escape function for JS pattern related strings
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
// Thanks to kouphax | |
RegExp.escape = function(str){ | |
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\ | |
return str.replace(specials, "\\$&"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment