Skip to content

Instantly share code, notes, and snippets.

@paganotoni
Created May 9, 2012 03:37
Show Gist options
  • Save paganotoni/2641622 to your computer and use it in GitHub Desktop.
Save paganotoni/2641622 to your computer and use it in GitHub Desktop.
Escape function for JS pattern related strings
// 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