匹配和replace每个“第二”出现的“,在Javascript中
我想用“。”(点)replace“(DoubleQuote逗号)
例如
“我全心全意,反而伤害了我的心”,“我们两人现在分开了”,“我的亲爱的人”,“我们的安慰是,悲伤之路如此清晰”,
应该:
"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.
尝试使用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!");