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?
 
    