给定以下代码:
alpha = ('"foo"="bar"').replace(/.*foo...([^"]*).*/, RegExp.$1)
beta = ('"bar"="baz"').replace(/.*bar...([^"]*).*/, RegExp.$1)
预期的输出是:
alpha is "bar"
beta is "bar"
实际输出为:
alpha is ""
beta is "bar"
这导致我找到了这个解决方法:
var alpha = beta = "", n = "\n";
('"foo"="bar"').match(/.*foo...([^"]*).*/);
alpha.toString.v1 = ('"foo"="bar"').replace(/.*foo...([^"]*).*/, RegExp.$1)
String('"bar"="baz"').replace(/.*bar...([^"]*).*/);
beta.toString.v2 = ('"foo"="baz"').replace(/.*foo...([^"]*).*/, RegExp.$1)
document.body.innerText += alpha.toString.v1 + n + alpha.toString.v2;
如何在不需要匹配更新反向引用的情况下执行此操作?