Answers for "javascript escape regex special characters"

0

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
0

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 January-01-1970

Code answers related to "javascript escape regex special characters"

Code answers related to "Javascript"

Browse Popular Code Answers by Language