Brendan Eich (2013-08-29T07:45:45.000Z)
domenic at domenicdenicola.com (2013-09-08T00:20:47.054Z)
Axel Rauschmayer wrote: > Really? AFAICT, only the complete matches (group 0) are returned. Sorry, of course you are right -- how soon I forget -- the subgroups show up only in each exec result array, but are dropped from the match result. So hair on the other side of the coin, if you will. A naive iterator that calls exec would return, e.g.,["ab", "b"] for the first iteration given r and s as follows: ``` js> r = /.(.)/g /.(.)/g js> s = 'abcdefgh' "abcdefgh" js> a = s.match(r) ["ab", "cd", "ef", "gh"] js> b = r.exec(s) ["ab", "b"] ``` Is this what the programmer wants? If not, String.prototype.match stands ready, and again takes away motivation for an eager execAll. But programmers wanting exec with submatches could use a lazy form: ``` js> r.lastIndex = 0 0 js> RegExp.prototype.execAll = function (s) { let m; while (m = this.exec(s)) yield m; } (function (s) { let m; while (m = this.exec(s)) yield m; }) js> c = [m for (m of r.execAll(s))] [["ab", "b"], ["cd", "d"], ["ef", "f"], ["gh", "h"]] ```