Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Expose lastIndex from iterator #7

Closed
RReverser opened this issue Nov 23, 2015 · 3 comments
Closed

Expose lastIndex from iterator #7

RReverser opened this issue Nov 23, 2015 · 3 comments
Labels

Comments

@RReverser
Copy link

We should probably still expose lastIndex from iterator object itself (as in opposite to old regexp-bound property). This can be useful for some cases like regexp with sticky flag, where we want to know whether our "tokenization" matched entire string or stopped somewhere in the middle as following text didn't match so that we could handle error / try another regexp / whatever.

Otherwise, /^regexp/y for regexpregexpregexp something something regexp and regexpregexpregexp returns same list of matches and it becomes impossible to figure out whether and where the error occured.

@ljharb
Copy link
Member

ljharb commented Jul 29, 2017

I think exposing it makes sense; how would you suggest exposing lastIndex?

Here are some options that come to mind:

  1. set an additional lastIndex property on the match object (normal match objects coming from exec only have input and index, and likely groups after named capture groups land).
  2. yield an array of [match, lastIndex]
  3. yield an object of { match, lastIndex }

@RReverser
Copy link
Author

Hmm I'm now trying to remember whether I simply misunderstood the original proposal (that it returns not just strings but also index) or had something else in mind. If we have index + match.length, it's probably sufficient to figure out if you matched entire string or not.

@ljharb
Copy link
Member

ljharb commented Sep 22, 2017

Awesome - in that case I'll close this out; but happy to reopen it if there's still something we need to add.

@ljharb ljharb closed this as completed Sep 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants