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
What about recursive version of you own solution?
function repalceLeadSpaces(str, substitution, n) { n = n || 0; if (!str || n <= 0) { return str; } str = str.replace(/\s+/, substitution); return n === 1 ? str : repalceLeadSpaces(str, substitution, n - 1) }