-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of concept: simulating sticky mode in pre-ES6 environemnts... #152
Comments
XRegExp already supports sticky mode for ES3+ using |
Ooh, that's nice, I had missed the sticky mode... IIUC with the current implementation, in sticky mode, the regexp still searches till the end of the subject and The snippet above doesn't search beyond the current index, but you have to create an extra RegExp object... It may be cached in the Interrested in a PR? |
Sure--I'm interested. :) Your implementation is clever and I'm not seeing obvious problems. Also If there are any loose ends, this approach probably wouldn't be worth it given that XRegExp already defers to native |
I think I've got something that match your criteria... Benchmarks ongoing in a pre ES6 Chromium derivative. Do you want me to include the generated BTW, these lines should also exclude sticky matches whose |
Yes please, but right now it's out of date. :-( I'll regenerate it ASAP (just need to run |
PR: #153 |
@slevithan Ok, don't worry about the out of date bundle, I'll add an intermediate commit with a build before the sticky-related changes and another one with the full build. I usually avoid adding build artifacts to PRs because it causes merge conflicts when other PRs are merged or other code is pushed in the mean time, but given the current activity on XRegExp we're safe (I hadn't looked at the GH pulse yet). |
Would you mind submitting a PR for this? |
The last remaining piece for this issue is the updates for |
It is possible, with some hand holding, to simulate sticky matching with normal RegExps.
By appending
|()
to the source, you ensure that the match will succeed no matter what at the given index. Iforiginal
doesn't match, the last capture will be''
,null
otherwise.The trouble now is to convince UAs to treat the resulting object as a RegExp in
String.prototype.*
context... I suppose that in ES6 you could extend native RegExps, but the polyfill is not needed there since ES6 introduces they
flag...Edit: now the code actualy works :)
The text was updated successfully, but these errors were encountered: