0

I have this function which is supposed to put all matches regex returns when executed against a string str into the array res and then return it:

function matchAll(str, regex) {
    var res = [];
    var m;

        while (m = regex.exec(str)) {
            res.push(m[0]);
        }

    return res;
}

It creates an infinite loop with the regex /^\d\d*/i. Why?

The SE I loved is dead
  • 1,517
  • 4
  • 23
  • 27

1 Answers1

0

Try this regex: \d\s[A-Z0-9]{3,3}

RegexPal (working solution): http://www.regexpal.com/?fam=96072

dchayka
  • 1,291
  • 12
  • 20