Skip to content

Instantly share code, notes, and snippets.

@rodu
Last active August 13, 2018 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodu/0b19ea1a253c3d808a51d9f86b98f24c to your computer and use it in GitHub Desktop.
Save rodu/0b19ea1a253c3d808a51d9f86b98f24c to your computer and use it in GitHub Desktop.
// Credits: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment