Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active April 2, 2019 19:26
Show Gist options
  • Select an option

  • Save vbarbarosh/a4eb5960bfe9c283b2ff64004d89e4a3 to your computer and use it in GitHub Desktop.

Select an option

Save vbarbarosh/a4eb5960bfe9c283b2ff64004d89e4a3 to your computer and use it in GitHub Desktop.
js_regex_escape – Make a string safe to put into regular expression https://codescreens.com
// Make a string safe to put into RegExp
// https://stackoverflow.com/a/6969486
// https://stackoverflow.com/a/3561711
function js_escape_regexp(s)
{
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment