如何替换以下字符串中前 N
个空格和制表符的多个出现:
07/12/2017 11:01 AM 21523 filename with s p a c e s.js
I am expecting the following result:
07/12/2017|11:01|AM|21523|filename with s p a c e s.js
我知道不是很优雅的方法,只能通过在同一个字符串上调用replace
N
次来完成。
.replace(/\s+/, "|").replace(/\s+/, "|").replace(/\s+/, "|");
值得一提的是,我将在接近100万行的数据上运行此程序,因此性能至关重要。
g
将替换所有内容。但我只需要替换前n个出现的。 - Systems Rebooter