Skip to content

Instantly share code, notes, and snippets.

@silentmatt
Created January 14, 2010 19:08
Show Gist options
  • Save silentmatt/277401 to your computer and use it in GitHub Desktop.
Save silentmatt/277401 to your computer and use it in GitHub Desktop.
Escape special characters in a regular expression
RegExp.escape = (function() {
var special = /([.*+?^${}()|[\]\/\\])/g;
return function escape(s) {
return s.replace(special, '\\$1');
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment