Letting RegExp method return something iterable?

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Aug 26 16:09:33 PDT 2013


Is it very useful because you wrote for instead of while ?

```javascript
while (m = re.exec(str))
  console.log(m[0])
;
```

I don't really see any concrete advantage, sorry, but maybe it's me not
liking at all this `iterable all the things` new trend.


On Mon, Aug 26, 2013 at 11:33 AM, Erik Arvidsson
<erik.arvidsson at gmail.com>wrote:

> On Mon, Aug 26, 2013 at 1:05 PM, Andrea Giammarchi
> <andrea.giammarchi at gmail.com> wrote:
>
> > Long story short, I don't see any real use/case or any concrete advantage
> > with those examples so please make it more clear what's the problem you
> are
> > trying to solve and how these methods will concretely make our life
> easier
> > ^_^
>
> Having a way to get an iterable over all the matches is highly useful.
> It is common to use such a construct in Python.
>
> ```py
> for m in re.finditer(r"\w+", "aa b ccc"):
>   print m.group(0)
> ```
>
> ```js
> for (let m of 'aa b ccc'.matchAll(/(\w+/)) {
>   print(m[0]);
> }
> ```
>
> --
> erik
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130826/f95abffd/attachment.html>


More information about the es-discuss mailing list