Skip to content

Instantly share code, notes, and snippets.

@gobwas
Created February 5, 2014 10:24
Show Gist options
  • Save gobwas/8820745 to your computer and use it in GitHub Desktop.
Save gobwas/8820745 to your computer and use it in GitHub Desktop.
RegExp escaper
var escaper = function(value) {
assert(_.isString(value), "Can escape only the strings");
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment