Answers for "new regexp dont escape +"

1

javascript escape regex

// Vanilla JS
function escapeRegex(string) {
  return string.replace(/[.*+?^${}()|[]\]/g, '\$&');
}

// Or with npm: npm install escape-string-regexp
const escapeRegex = require('escape-string-regexp');

// Usage:
const regex = new RegExp(escapeRegex('How much $ is that?'));
Posted by: Guest on July-23-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language