4

This works fine in Chrome

const expression = '(?<=\\d) (\\d\\d\\d)';
const regex = new RegExp(expression, 'gmi');
'123 456'.replace(regex, 'z$1')
// 123z456

However using karma with babelify I get the following error with phantomjs

SyntaxError: Invalid regular expression: unrecognized character after (?

and with Firefox 62.0.0

SyntaxError: invalid regexp group (same as when using the browser directly)

Is there a plugin that I'm missing ?

http://2ality.com/2017/05/regexp-lookbehind-assertions.html

https://babeljs.io/docs/en/plugins/#es2018

pansay
  • 687
  • 8
  • 11
  • 4
    Lookarounds are really hard to emulate, they need to be built into the regexp engine. Babel probably can't doit. – Barmar Nov 04 '18 at 00:04

0 Answers0