Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created October 29, 2016 04:48
Show Gist options
  • Select an option

  • Save gkucmierz/50a39f9b52c4d2a3fa7902d3d7330aec to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/50a39f9b52c4d2a3fa7902d3d7330aec to your computer and use it in GitHub Desktop.
Escape string for RegExp
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