Javascript loop regex matches

Date: 2019-04-19
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
(() => {
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);
}
})();
(() => { 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); } })();
(() => {

    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);
    }

})();

21010cookie-checkJavascript loop regex matches
0 of 2000 max characters.