How can I replace first N occurrences of many whitespaces and tabs in the following string:
N
07/12/2017 11:01 AM 21523 filename with
Derek and Nina provide great answers for dynamically replacing N whitespace groups. If N is static, the non-whitespace token (\S) can be used to match and keep the groups between whitespace:
\S
.replace(/\s+(\S+)\s+(\S+)\s+/, '|$1|$2|')