-
Notifications
You must be signed in to change notification settings - Fork 12
Always start from the beginning of string #5
Comments
One interesting collision between this and #6 is that the whole point of the I wonder if it would be better, instead of ignoring |
Not really - you still do use and respect sticky flag and respect
In all those case, |
(I believe this comment / discussion belongs to #6 more, so let's continue there) |
OK, given the direction from #6, I think this question still applies. I think the possible ways to handle
In all cases, One thing I think it's important to consider here is that the trivial case - a literal regex on a small string - is not the only thing this needs to account for. RegExp subclasses might exist that would match infinitely, for example - or, this might simply be a very very large portion of text, and you might know you already want to skip it - and simply slicing the large string might not be friendly to memory or performance. I think there does need to be some way for the user to provide a starting index, and my initial thought was to just use the conventional method for this - the |
Not really - as I pointed, none of engines actually copies substrings on slicing as they're immutable, instead they create minimalisting object that just points to the same memory and contains offset + length of the chunk. There were even a lot of complaints from V8 users that one-character slice of a huge string prevents GC from collection original string at all during the lifetime of this slice. Of course, this can be considered implementation-specific, but if we're taking performance into account, it's impl-specific anyway, and currently any engine deals well with it.
Probably you're right... It's just that taking |
@RReverser Can you file a new issue for that last one? |
Deleted comment here, raised as #7. |
What's the conclusion here--should we copy the lastIndex over, or always start from 0? (Note: I imagine a common use case will be to use a particular RegExp only with matchAll, and that would make this issue not come up.) Personally, I would've expected the always-start-from-0 behavior; lastIndex in the source RegExp feels more like something to trip up on than anything else. |
I think that the existence of the sticky flag makes lastIndex something we can't ignore; "sticky" is something for people to trip up on already, and we can't just gloss over it. Per #5 (comment), I think we have to respect |
Closing, since we're going to stick with respecting |
[Continuation of Twitter discussion]
Currently proposal uses stored
lastIndex
instead of starting with the beginning of string, which makes it confusing when used in combination with <=ES5 methods that do make use oflastIndex
and thus iterator will start from an implicit internal position from unrelated call and won't really "match all" occurences as naming implies.IMO, it would make more sense to always start from the beginning of the string, so that iterator wouldn't conflict with earlier
exec
calls and would behave in the same way independently from context.The text was updated successfully, but these errors were encountered: