How can I replace first N
occurrences of many whitespaces and tabs in the following string:
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
I know not very elegant option only via calling replace N
times on the same string
.replace(/\s+/, "|").replace(/\s+/, "|").replace(/\s+/, "|");
Worth to mention that I'm going to run this on near 1,000,000 lines so performance matters.
g
will replace everything. But i need to replace only firstn
occurrences