在mongodb正则表达式中匹配多字节utf8字符 [英] matching multibyte utf8 characters in mongodb regular expression

查看:67
本文介绍了在mongodb正则表达式中匹配多字节utf8字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用这样的正则表达式来搜索我的一个集合

im trying to search one of my collections using a regular expression like this

db.tweets.find({tweet_text:new RegExp("\u[\x{0621}-\x{0670}]")},{tweet_text:1})

但出现错误提示:星期二 3 月 27 日 15:16:58 语法错误:字符类(shell)中的范围无效:1

but an error occurs saying: Tue Mar 27 15:16:58 SyntaxError: invalid range in character class (shell):1

在 php 和 perl i 使用相同的正则表达式并添加\u"选项以指示使用 utf8 并且它运行良好问题是 mongodb regex 没有这个选项,是否有替代它?!

in php and perl i use the same regular expression and add the "\u" option to indicate using utf8 and it works well the problem is that mongodb regex does not have this option,is there an alternative to it?!

推荐答案

javascript 中 RegExp 的正确语法是:

The correct syntax for RegExp in javascript is:

new RegExp("[\u0621-\u0670]");

这篇关于在mongodb正则表达式中匹配多字节utf8字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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