(() => { function* matches(re, str) { for (let m; m = re.exec(str);) { yield m[1]; } } function* map(iter, mapping) { for(let c = iter.next(); !c.done; c = iter.next()) { yield mapping(c.value); } } const lpad = (x, l, f) => String(x).padStart(l, f); const padNumArray = (re, str) => map(matches(re, str), x => lpad(Number(x), 4, "0")); for (const paddedNumber of padNumArray(/(\d+)/g, "12,45,78,89,5,1,306")) { console.log(paddedNumber); } })();
210100cookie-checkJavascript loop regex matches