[英]Escaping special character in Mongodb regex
I am trying to match 我正在尝试搭配
"Mozilla/5.0 (Linux; U; Android 4.0.4; fr-ca; GT-S7560M Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko)"
with 与
"Mozilla/5.0 (Linux; U; Android 4.0.4; fr-ca; GT-S7560M Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
I am using the following query 我正在使用以下查询
function regexEscape(string){
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
var ua = regexEscape(user_string)
db.collection.find({ua:{$regex:'*.'.concat(ua,'.*'),$options:'si'}).count()
But the result is 0. 但是结果是0。
Can you guys tell me where I am going wrong? 你们能告诉我我要去哪里吗?
经过大量的努力,我发现了错误,
db.collection.find({ua:{$regex:us.concat(".*"),$options:'si'}}).count()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.