0

I want to replace a regular expression (a string), the string is url(../img/content/blocks.svg) no-repeat scroll transparent;

My script is

var content = content.replace(/url(../img/content/blocks.svg) no-repeat scroll transparent;/g, "none;");

This makes an error : Uncaught SyntaxError: Unexpected identifier

Sushi
  • 646
  • 1
  • 13
  • 31

1 Answers1

0

The string to be replaced is a perfect candidate for non-regex based replacement in your case. Unfortunately, JavaScript lacks replaceAll, but you may mimic it by combining split and join:

input.split('replace what').join('with what')

Demo:

var content = 'some text url(../img/content/blocks.svg) no-repeat scroll transparent; some text url(../img/content/blocks.svg) no-repeat scroll transparent; some text';
var output = content.split('url(../img/content/blocks.svg) no-repeat scroll transparent;').join('none;');
console.log(output);
Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40