Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 2x 7x 4x 7x 1x | /** * It executes the sepecified regexp for the given text and executes the callback with the match. If a global regexp is used, it creates a loop. * @param {RegExp} regexp - Regular expression * @param {string} text - Text * @param {function} cb - Callback function */ function regexLoop(regexp, text, cb) { let match while((match = regexp.exec(text)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if(match.index === regexp.lastIndex) regexp.lastIndex++ cb(match) } } module.exports = regexLoop |