Why does not Lookbehind exist in JavaScript?

6

I found out that there is no group construct lookbehind in Regex's made in JavaScript so I had some questions like:

  • Why does not it exist? Home Is there any reason that makes it incompatible with language or unnecessary?
  • If it is unnecessary, is there an alternative to using lookbehind that causes the same result?
  • Why does this language only have this group construct ?
asked by anonymous 25.05.2017 / 19:19

1 answer

4

After some time studying the subject I came up with the following conclusions:

  

Why does not it exist ( negative/positive lookbehind )?

It seems that Brendan Eich did not know of its existence at the time , because Netscape was made in an old version of Perl . Even so, after some time some implementation attempts have been made, but unsuccessful because of the complexity of implementation, because Regular Expressions in EcmaScript work from #, which is also required for the use of lookbehind, so if the use of lookbehind is incorrect it could lead to some problems such as catastrophic backtracking .

  

Is there any reason that makes it incompatible with language or unnecessary?

It is not incompatible or impossible to implement, but it has not yet presented a performative way of implementation, however there is a proposal that is already in stage 3 of implementation so that the use of lookbehind is compatible with EcmaScript. I would not call it unnecessary, since there is performance gain by using group construct lookahead or lookbehind

  

[...] Is there an alternative to using lookbehind that causes the same result?

If we do not consider performance , you can achieve the same results using multiple capture groups or even lookahead's in the same expression. As you can see in this example .

  

Why does this language only have this group construct?

As already mentioned, it is really difficult to do something performative and stable behavior when used with other tokens and group constructs , but since it is already stage 3 implementation in EcmaScript, I believe this will not be true for long.

    
10.10.2017 / 16:03