Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.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 - Fatal编程技术网

匹配字符串中的Javascript正则表达式

匹配字符串中的Javascript正则表达式,javascript,regex,Javascript,Regex,我有这样的绳子 <html> [[Wayfinder? &amp;startId=`0` &amp;outerClass=`art-hmenu` ]] &amp; &amp; </html> [[Wayfinder?&;startId='0`&;outerClass='art Humenu`]&; &; 我想更改所有&内部的[[和]将替换为& 如何使用javascript实现这一点 st

我有这样的绳子

<html>
    [[Wayfinder? &amp;startId=`0` &amp;outerClass=`art-hmenu` ]] &amp;
    &amp; 
</html>

[[Wayfinder?&;startId='0`&;outerClass='art Humenu`]&;
&;
我想更改所有
&内部的
[[
]
将替换为
&

如何使用javascript实现这一点

str.replace(/\[\[(.*)?]]/, function(match) {
    return match.replace(/&amp;/g, '&');
});
这是小提琴:


这里是小提琴:

更好:把
/\[\[(.*)?\]\]/
改成
/\[\[(.{4})?\]\]/
@qwertymk-我真的不知道这有什么好处。如果里面的文本长度小于4个字符,它将阻止第二个正则表达式运行。没有那么大的好处。更好的方法是:将
/\[\[(.*)\]\]/
更改为
/\[\[(.{4})\]\]/
@qwertymk-我真的看不出这有什么好处。如果里面的文本长度小于4个字符,它将阻止第二个正则表达式运行。其实没什么好处。