Skip to content

Instantly share code, notes, and snippets.

Created January 7, 2013 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4474574 to your computer and use it in GitHub Desktop.
Save anonymous/4474574 to your computer and use it in GitHub Desktop.
simple method to escape strings so they can be used as RegEx patterns
// taken from http://stackoverflow.com/a/6969486/1734964
// saved for my own laziness
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment