8

Does JavaScript support positive and/or negative lookaheads/lookbehinds? Which combinations of them? Or, to be more specific:

  1. Positive lookaheads
  2. Negative lookaheads
  3. Positive lookbehinds
  4. Negative lookbehinds
Mario Rossi
  • 7,651
  • 27
  • 37

3 Answers3

7

Here in 2020 some browsers do also support lookbehind (lookahead has been supported from the beginning):

  • IE no support
  • Edge 79+
  • Firefox 78+ (very fresh)
  • Chrome 62+
  • Safari no support
  • Opera 49+

Source: https://caniuse.com/#search=Lookbehind

Maxim Kulikov
  • 699
  • 7
  • 15
3

Javascript has support for only positive and negative lookahead with no support whatsoever for lookbehinds, but you can still mimic the latter in Javascript using callbacks.

There is a nice article about this here, actually although this article uses callbacks to provide some sort of an alternative support for lookbehind, the same principle can be used in other languages that support lookbehinds but not variable expressions in them so it is handy trick.

Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
2

JavaScript doesn't support any lookbehind, but it can support lookaheads.

So:

  1. Yes
  2. Yes
  3. No
  4. No

You can find more details about the specifics of JavaScript regex on this page.

Jerry
  • 70,495
  • 13
  • 100
  • 144