Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我无法使用正则表达式和变量替换字符_Javascript_Regex_Replace - Fatal编程技术网

Javascript 我无法使用正则表达式和变量替换字符

Javascript 我无法使用正则表达式和变量替换字符,javascript,regex,replace,Javascript,Regex,Replace,我一直在尝试在Javascript代码中使用正则表达式来缩小指示的差距,如下所示。但我无法做到这一点 这是有效的 outputFile=outputFile.replace(/\s*您必须将所有\s转义到\\,因为您将正则表达式定义为字符串,而不是正则表达式文本 new RegExp("\\s*<"+htmlElements[0], 'g') new RegExp(“\\s*仍不清楚您想要什么 new RegExp("\\s*<"+htmlElements[0], 'g')

我一直在尝试在Javascript代码中使用正则表达式来缩小指示的差距,如下所示。但我无法做到这一点

这是有效的

outputFile=outputFile.replace(/\s*您必须将所有
\
s转义到
\\
,因为您将正则表达式定义为字符串,而不是正则表达式文本

new RegExp("\\s*<"+htmlElements[0], 'g')

new RegExp(“\\s*仍不清楚您想要什么
new RegExp("\\s*<"+htmlElements[0], 'g')