我想替换正则表达式(字符串),字符串是url(../img/content/blocks.svg) no-repeat scroll transparent;
我的脚本是
var content = content.replace(/url(../img/content/blocks.svg) no-repeat scroll transparent;/g, "none;");
这会出错:Uncaught SyntaxError: Unexpected identifier
答案 0 :(得分:0)
在您的情况下,要替换的字符串是非正则表达式替换的完美候选者。遗憾的是,JavaScript缺少replaceAll
,但您可以通过合并split
和join
来模仿它:
input.split('replace what').join('with what')
演示:
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);