Letting RegExp method return something iterable?

Brendan Eich brendan at mozilla.com
Wed Aug 28 17:39:40 PDT 2013


Ron Buckton wrote:
> The advantage of a lazy execAll, is the ability to break out of the 
> for..of loop without the need to continue to traverse the input string 
> looking for matches. This is the same advantage that the `while(m = 
> re.exec())` has going for it. You can always be greedy by using 
> Array.from or an array comprehension if execAll is lazy, but you are 
> back to using a while loop if execAll is greedy and you want lazy 
> matching, which limits its usefulness in some scenarios.

Good point -- on top of the quasi-redundancy of an eager execAll viz. 
String.prototype.match, I think this makes a good case for a lazy 
execAll -- with a much better name.

Candidates: r.iterate(s), r.iterateOver(s), r.execIterator(s) (blech!). 
Suggest some!

/be


More information about the es-discuss mailing list