MongoDB \uXXXX 问题 [英] MongoDB \uXXXX issue

查看:41
本文介绍了MongoDB \uXXXX 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的集合中,以下查询返回一些结果:

In my collection following query returns some result:

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

但是下面的查询(以及任何其他具有 \uXXXX 的正则表达式)不返回任何结果:

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

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

怎么了?

推荐答案

这样做的原因是根据 文档

The reason for this is that according to the documentation

MongoDB 使用 PCRE 来处理正则表达式.

MongoDB uses PCRE for regular expressions.

但是 PCRE 文档说

However the PCRE documentation says

不支持以下 Perl 转义序列:\l、\u、\L、\U 和 \N 后跟字符名称或 Unicode 值.(\N 开它自己的,匹配一个非换行符,被支持.)实际上这些由 Perl 的一般字符串处理实现,不属于它的模式匹配引擎.如果 PCRE 遇到这些中的任何一个,默认情况下会生成错误.但是,如果 PCRE_JAVASCRIPT_COMPAT选项被设置,\U 和 \u 被解释为 JavaScript 解释

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.

这篇关于MongoDB \uXXXX 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆