Letting RegExp method return something iterable?

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


Forbes Lindesay wrote:
> Let’s move on from whether it should exist (clearly it should)

Does String.prototype.match not count?

> and stick to whether it should be an array, or lazy. Does anyone have 
> a strong opinion either way? The fact that all our regular expression 
> iteration thus far has been lazy to me suggests this probably should 
> be too, but maybe it would be simpler if it returned an array. I 
> really hope someone will chime in on this.

The fact that s.match(/re/g) returns the array of all matches (with 
captures) sucks some of the oxygen away from any /re/g.execAll(s) proposal.

But String.prototype.match has perlish hair (e.g., those capture groups 
showing up in the result array). Perhaps we do want execAll (with a 
better name) just to break down the composite perl4-era legacy into 
compositional methods.

/be


More information about the es-discuss mailing list