2

In my collection following query returns some result:

db.c.find({t:/a/})

But below query (and any other regex that has \uXXXX) returns no result:

db.c.find({t:/\u0041/})

What is wrong?

Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173

2 Answers2

3

Using Ray Toal's answer, Using PCRE \x{XXXX} syntax instead of JavaScript \uXXXX solved problem.

db.c.find({t:/\x{0041}/})
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
2

The reason for this is that according to the documentation

MongoDB uses PCRE for regular expressions.

However the PCRE documentation says

The following Perl escape sequences are not supported: \l, \u, \L, \U, and \N when followed by a character name or Unicode value. (\N on its own, matching a non-newline character, is supported.) In fact these are implemented by Perl's general string-handling and are not part of its pattern matching engine. If any of these are encountered by PCRE, an error is generated by default. However, if the PCRE_JAVASCRIPT_COMPAT option is set, \U and \u are interpreted as JavaScript interprets them.

That said, this SO question may be of some help.

Community
  • 1
  • 1
Ray Toal
  • 86,166
  • 18
  • 182
  • 232