-
Notifications
You must be signed in to change notification settings - Fork 27
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
RegExp lookbehind assertions #171
Comments
Here are some tweets about this that we've come across: |
to note that one of the reasons that Firefox implemented it was webcompat pressure. such as steam community chat |
#169 would beg to differ 🙃 (plus, of course, several weeks remaining for others to submit such proposals!) |
I stand corrected :) Regardless, my offer to write WPT tests if needed still stands. |
RegExp lookbehind assertions is a P2 for Google's closure library "Consolidate functionality across browsers; potentially replace some string library usage and generally improve code health if used appropriately." |
Thank you for proposing RegExp lookbehind assertions for inclusion in Interop 2023. We are pleased to let you know that this proposal was accepted as part of the Web Compat 2023 focus area. You can follow the progress of this Focus Area on the Interop 2023 dashboard. For an overview of our process, see the proposal selection summary. Thank you for contributing to Interop 2023! Posted on behalf of the Interop team. |
Description
Lookarounds are zero-width assertions that match a string without consuming anything. ECMAScript has long supported lookahead assertions that do this in forward direction. Positive lookahead ensures a pattern is followed by another pattern, and negative lookahead ensures a pattern is not followed by another pattern.
ES2018 added support for lookbehind assertions, which are lookarounds that go backwards. Positive lookbehind ensures a pattern is preceded by another pattern, and negative lookbehind ensures a pattern is not preceded by another pattern.
Rationale
Lookbehinds enable developers to ensure that a pattern is or isn’t preceded by another, which is a common use case when dealing with regular expressions — e.g. matching a dollar amount without capturing the dollar sign:
Or, conversely, matching numbers that aren’t dollar amounts:
Unlike many other JavaScript language features, lookbehind support cannot accurately be polyfilled or transpiled. Only interoperable engine-level support can fill the gap.
Chrome 62 (stable in 2017-10) and Firefox 78 (stable in 2020-06) have shipped support, but until all browsers provide support, compatibility issues continue to pop up. Examples:
Specification
https://tc39.es/ecma262/#prod-Assertion
Tests
https://test262.report/browse/built-ins/RegExp/lookBehind?engines=javascriptcore%2Cspidermonkey%2Cv8 (corresponding to https://github.com/tc39/test262/tree/main/test/built-ins/RegExp/lookBehind)
Note that since there are no other Interop proposals that need tests from Test262, it would be overkill to set up full Test262 integration just for this one feature. If this proposal is accepted, I volunteer to write equivalent WPT tests for this feature.
Update: web-platform-tests/wpt#37928
The text was updated successfully, but these errors were encountered: