Re: [v8-dev] Intent to Ship: RegExp @@matchAll / String.prototype.matchAll

24 views
Skip to first unread message

Sathya Gunasekaran

unread,
Dec 13, 2018, 6:27:22 PM12/13/18
to v8-...@googlegroups.com, v8-users, blink-dev, Jakob Gruber, yan...@chromium.org, Mathias Bynens
LGTM
On Thu, Dec 13, 2018 at 2:01 PM Peter Wong <peter....@gmail.com> wrote:
>
> Contact emails
> peter....@gmail.com
> jgr...@chromium.org
> yan...@chromium.org
>
> mat...@chromium.org
>
>
> Spec
> https://github.com/tc39/proposal-string-matchall/
>
> https://tc39.github.io/proposal-string-matchall/
>
>
> Summary
> String.prototype.matchAll behaves similarly to String.prototype.match, but returns a full regexp result object for each match in a global or sticky regexp.
>
> Motivation
> This offers a simple way to iterate over matches when access to e.g. capture groups is needed.
>
> const string = 'Magic hex numbers: DEADBEEF CAFE 8BADF00D';
> const regex = /\b[0-9a-fA-F]+\b/g;
> for (const match of string.matchAll(regex)) {
> console.log(match);
> }
>
> // Iteration 1:
> [
> 'DEADBEEF',
> index: 19,
> input: 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
> ]
>
> // Iteration 2:
> [
> 'CAFE',
> index: 28,
> input: 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
> ]
>
> // Iteration 3:
> [
> '8BADF00D',
> index: 33,
> input: 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
> ]
>
>
> Interoperability risk
> Firefox: In development - https://bugzilla.mozilla.org/show_bug.cgi?id=1435829
> Edge: No public signals
> Safari: No public signals - https://bugs.webkit.org/show_bug.cgi?id=186694
> Web developers: Positive
>
> Compatibility risk
> The spec has undergone a few updates and depending on whether other implementations have kept up, there is a possibility V8 could differ in behavior. At the time of writing, V8 is current with all the latest spec updates and have contributed updates to the test262 test suite to minimize difference between other implementations.
>
>
> V8 tests (mjsunit) as well as all test262 tests pass for this feature.
>
> Will this feature be supported on all six Blink platforms (Windows, Mac, Linux,
> Chrome OS, Android, and Android WebView)?
>
> Yes
>
> Link to entry on the Chrome Platform Status
> https://www.chromestatus.com/features/5520028858318848
>
> Requesting approval to ship?
> Yes. Note that since this is a V8/JS feature, this post is just an FYI to blink-dev — no signoff from Blink API owners is required.
>
>
> --
> --
> v8-dev mailing list
> v8-...@googlegroups.com
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter Wong

unread,
Dec 13, 2018, 7:19:37 PM12/13/18
to blink-dev, jgr...@chromium.org, yan...@chromium.org, mat...@chromium.org

Contact emails
peter....@gmail.com
jgr...@chromium.org
yan...@chromium.org

mat...@chromium.org


Spec
https://github.com/tc39/proposal-string-matchall/

https://tc39.github.io/proposal-string-matchall/


Summary
String.prototype.matchAll behaves similarly to String.prototype.match, but returns a full regexp result object for each match in a global or sticky regexp.

Motivation
This offers a simple way to iterate over matches when access to e.g. capture groups is needed.

 

Interoperability risk
Firefox: In development - https://bugzilla.mozilla.org/show_bug.cgi?id=1435829
Edge: No public signals
Safari: No public signals - https://bugs.webkit.org/show_bug.cgi?id=186694
Web developers: Positive

Compatibility risk
The spec has undergone a few updates and depending on whether other implementations have kept up, there is a possibility V8 could differ in behavior.  At the time of writing, V8 is current with all the latest spec updates and have contributed updates to the test262 test suite to minimize difference between other implementations.

Peter Wong

unread,
Dec 13, 2018, 7:19:42 PM12/13/18
to v8-...@googlegroups.com, v8-u...@googlegroups.com, blin...@chromium.org, jgr...@chromium.org, yan...@chromium.org, mat...@chromium.org

Contact emails
peter....@gmail.com
jgr...@chromium.org
yan...@chromium.org

mat...@chromium.org


Spec
https://github.com/tc39/proposal-string-matchall/

https://tc39.github.io/proposal-string-matchall/


Summary
String.prototype.matchAll behaves similarly to String.prototype.match, but returns a full regexp result object for each match in a global or sticky regexp.

Motivation
This offers a simple way to iterate over matches when access to e.g. capture groups is needed.

const string = 'Magic hex numbers: DEADBEEF CAFE 8BADF00D';

const regex = /\b[0-9a-fA-F]+\b/g;
for (const match of string.matchAll(regex)) {
 console
.log(match);
}

// Iteration 1:
[
 
'DEADBEEF',
 index
: 19,
 input
: 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
]

// Iteration 2:
[
 
'CAFE',
 index
: 28,
 input
: 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
]

// Iteration 3:
[
 
'8BADF00D',
 index
: 33,
 input
: 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
]

Interoperability risk
Firefox: In development - https://bugzilla.mozilla.org/show_bug.cgi?id=1435829
Edge: No public signals
Safari: No public signals - https://bugs.webkit.org/show_bug.cgi?id=186694
Web developers: Positive

Compatibility risk
The spec has undergone a few updates and depending on whether other implementations have kept up, there is a possibility V8 could differ in behavior.  At the time of writing, V8 is current with all the latest spec updates and have contributed updates to the test262 test suite to minimize difference between other implementations.

Adam Klein

unread,
Dec 13, 2018, 7:57:31 PM12/13/18
to Sathya Gunasekaran, v8-...@googlegroups.com, v8-users, blink-dev, Jakob Gruber, Yang Guo, Mathias Bynens
LGTM2

You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAMd%2BM7zTAcnN5Aqwr1XdpBfd45Het_nOq2%3Deu6U_TvTRRDtVOQ%40mail.gmail.com.

Mathias Bynens

unread,
Dec 14, 2018, 5:50:40 AM12/14/18
to v8-...@googlegroups.com, gsa...@chromium.org, v8-users, blink-dev, Yang Guo
LGTM∞

On Fri, Dec 14, 2018 at 7:37 AM Jakob Gruber <jgr...@chromium.org> wrote:
LGTM3

PhistucK

unread,
Dec 14, 2018, 7:18:02 AM12/14/18
to peter....@gmail.com, v8-...@googlegroups.com, v8-users, blink-dev, jgr...@chromium.org, Yang Guo, Mathias Bynens
Can you make the example clearer?
["...", index: 0, input: "..."] is unfamiliar, invalid syntax.

PhistucK


--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAAKm-Q%2BuNU%3D%2BbSgu87THKGedRbf1OuCQSsJbmRgK5iPWAVO%2BDA%40mail.gmail.com.

Peter Wong

unread,
Dec 14, 2018, 1:39:36 PM12/14/18
to blink-dev
Hi PhistucK,

Thanks for the feedback.  Hopefully the following is clearer:

const string = 'Magic hex numbers: DEADBEEF CAFE 8BADF00D';
const regex = /\b[0-9a-fA-F]+\b/g;

for (const match of string.matchAll(regex)) {

 console
.log(`${match[0]} at ${match.index} with '${match.input}'`);
}

// > DEADBEEF at 19 with 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
// > CAFE at 28 with 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'
// > 8BADF00D at 33 with 'Magic hex numbers: DEADBEEF CAFE 8BADF00D'

PhistucK

unread,
Dec 14, 2018, 1:56:07 PM12/14/18
to peter....@gmail.com, blink-dev
Thank you.

If the pattern has groups, the array will have more than one item, right (I guess this is the most important benefit of this feature)?

PhistucK


Benedikt Meurer

unread,
Dec 15, 2018, 5:24:37 PM12/15/18
to v8-u...@googlegroups.com, peter....@gmail.com, v8-...@googlegroups.com, blink-dev, jgr...@chromium.org, Yang Guo, Mathias Bynens
LGTM!

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--

Benedikt Meurer

Software Engineer

bme...@google.com


Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.

    

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.

Jakob Gruber

unread,
Dec 15, 2018, 5:24:41 PM12/15/18
to v8-...@googlegroups.com, gsa...@chromium.org, v8-u...@googlegroups.com, blin...@chromium.org, Yang Guo, mat...@chromium.org
LGTM3

On Fri, Dec 14, 2018 at 1:57 AM Adam Klein <ad...@chromium.org> wrote:

Mathias Bynens

unread,
Dec 17, 2018, 3:08:02 AM12/17/18
to PhistucK, Peter Wong, blink-dev
Sure, but I wouldn't say that's a benefit of this particular feature -- it's just how String#match works. String#matchAll is like String#match, except it returns an iterator for all matches (instead of just getting the first match).

PhistucK

unread,
Dec 17, 2018, 3:40:06 AM12/17/18
to Mathias Bynens, Peter Wong, blink-dev
match returns groups if the regular expression is not a global one, matchAll returns groups regardless of the global-ness, this is significant (the explainer shows a lot of code that compensates for that problem, if I read it correctly). Sounds significant to me.

PhistucK

Mathias Bynens

unread,
Dec 17, 2018, 3:53:02 AM12/17/18
to PhistucK, Peter Wong, blink-dev
What I meant is the following:

const string = 'Magic hex numbers: DEADBEEF CAFE 8BADF00D';
const regex = /\b([0-9a-fA-F]{2})([0-9a-fA-F]+)\b/g);
[...string.match(regex)];
// --> ["DEADBEEF", "CAFE", "8BADF00D"]
[...string.matchAll(regex)];
// --> [["DEADBEEF", "DE", "ADBEEF"], ["CAFE", "CA", "FE"], ["8BADF00D", "8B", "ADF00D"]]

(My previous email said "match" which should've said "capturing group".)

I see what you're saying, PhistucK; an example with capturing groups would have demonstrated more about matchAll's functionality. I'll go ahead and update the ChromeStatus example. Thanks!
Reply all
Reply to author
Forward
0 new messages