var s= "this is inline $\alpha$, $$not$$";
Run Code Online (Sandbox Code Playgroud)
我怎样才能更换'$'by '%%'而不是'$$'.
这样输出就是
var s= "this is inline %%\alpha%%, $$not$$";
Run Code Online (Sandbox Code Playgroud)
我刚在想
s.split('$').join('%%')
Run Code Online (Sandbox Code Playgroud)
但我需要分成一美元而不是两美元.
你可以使用回调和贪心量词:
s.replace(/\$+/g, function(match) {
return match.length === 1 ? '%' : match;
});
Run Code Online (Sandbox Code Playgroud)