我想将“,(DoubleQuote逗号)”的每一次出现替换为“。”(点)
E.g。
“尽我的意愿,但更多的是反对我的心”, “我们现在两个人”, “我非常亲爱的”, “我们的安慰是,悲伤的道路如此清晰”,
应该是:
"With all my will, but much against my heart",
"We two now part.
"My Very Dear",
"Our solace is, the sad road lies so clear.
答案 0 :(得分:3)
尝试使用split
后跟reduce
,如下所示
<强>演示强>
var input = `"With all my will, but much against my heart",
"We two now part",
"My Very Dear",
"Our solace is, the sad road lies so clear",`
console.log( input.split( /",/ ).reduce( (a,b, i) => i %2 == 0 ? a + "\"," + b : a + "." + b ) );
console.log("It does the trick but it starts from the first line!");
&#13;