Skip to content

Instantly share code, notes, and snippets.

@robclancy
Created January 30, 2014 06:23
Show Gist options
  • Save robclancy/8703569 to your computer and use it in GitHub Desktop.
Save robclancy/8703569 to your computer and use it in GitHub Desktop.
JavaScript: escape regex
var escapeRegex = function(regex) {
return regex.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment