Does Mongo Shell support negative look-behind assertion?

Mongo Shell Support For Negative Lookbehind RegExp,

'cccddd'.replace(/(?<!c)d/g, 'A')
Replace all  `d`  not preceded by  `c`  with  `A`

Browser console:


However if I run this into mongo shell

MongoDB shell version v4.2.2
MongoDB server version: 4.2.2

> 'cccddd'.replace(/(?<!c)d/g, 'A')
2020-08-15T19:07:15.871+0530 E QUERY [js] uncaught exception: SyntaxError: 
invalid regexp group :

I can’t find any definitive documentation on what Mongo shell supports insofar, but it appears it doesn’t support negative look-behind (at least).

This works in the new MongoDB Shell.


You can install it from the download center or if you are on macOS with homebrew:

$ brew tap mongodb/brew
$ brew install mongosh

Thanks @Massimiliano_Marcon, it is working in new MongoDB Shell.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.