Why are lookbehind assertions not supported in Javascript?

Today

Lookbehind is now an official part of the ES 2018 specification. Axel Rauschmayer gives a good introduction in his blog post.

History

It looks like at the time, Brendan Eich wasn’t aware of its existence (because Netscape was built on an older version of Perl):

This was 1998, Netscape 4 work I did in ’97 was based on Perl 4(!), but we proposed to ECMA TC39 TG1 (the JS group — things were different then, including capitalization) something based on Perl 5. We didn’t get everything, and we had to rationalize some obvious quirks.

I don’t remember lookbehind (which emerged in Perl 5.005 in July ’98) being left out on purpose. Waldemar may recall more, I’d handed him the JS keys inside netscape.com to go do mozilla.org.

If you are game to write a proposal or mini-spec (in the style of ES5 even), let me know. I’ll chat with other TC39’ers next week about this.

/be

There have been a bunch of different on the mailing list with attempts to include it, but it still seems to be a pretty complex feature performance-wise, because EcmaScript Regular Expressions are backtracking based and backtracking is needed in lookbehind when working with capturing groups. This can lead to problems such as catastrophic backtracking when used incorrectly.

At some point it was suggested for ES6/Es 2015, but it never made the draft, let alone the specification. In the last post in the discussion, it seems that nobody took up the task of implementing it. If anybody feels called to write an implementation, they can sign up for the ES Discuss list and propose it.

Update May 2015:

In May 2015, Nozomu Katō has proposed an ES7 look-behind implementation.

Update September 2015:

Regex Look-behind was added as a stage 0 proposal.

Update May 2017:

The proposal is now at stage 3. This means that now at least two browsers need to implement it for it to become a part of the next EcmaScript standard. As @martixy mentioned in the comments, Chrome has implemented it behind the JS experimental flag.

Leave a Comment