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:

cccdAA

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 :
@(shell):1:17

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.

image.

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

$ brew tap mongodb/brew
$ brew install mongosh
3 Likes

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.