【发布时间】:2020-01-16 09:44:48
【问题描述】:
\s regex 通配符不匹配 mongodb (v4.0.3) 中所有类型的空间
> db.test.insertOne({ "mail" : "special email@example.com" })
> db.test.insertOne({ "mail" : "normal email@example.com" })
> db.test.find({ mail: / / }, { _id: 0, mail: 1 })
{ "mail" : "special email@example.com" }
> db.test.find({ mail: /\s/ }, { _id: 0, mail: 1 })
{ "mail" : "normal email@example.com" }
上面special email@example.com中的空间 是特殊空间,normal email@example.com中的普通空间
这是预期的还是错误?有没有办法让它匹配所有的空格?
旁注:我在$not 中运行正则表达式,所以我不能使用$regex
编辑:即使[^\S] 也不匹配两个字符串
> db.test.find({ mail: /[^\S]/ }, { _id: 0, mail: 1 })
{ "mail" : "normal email@example.com" }
mongo 正则表达式是否仅适用于 ASCII?
【问题讨论】:
-
您的“特殊”空间究竟是什么?比较
\s(MDN)的定义。 -
好吧,JS 中的
/\s/匹配两个字符串。/\s/.test("special email@example.com") === /\s/.test("normal email@example.com")是true -
两个字符串的btoa 看起来如何?
-
对于带有
The string to be encoded contains characters outside of the Latin1 range的特殊电子邮件失败。普通邮件一封给bm9ybWFsIGVtYWlsQGV4YW1wbGUuY29t -
btoa(unescape(encodeURIComponent("special email@example.com")))==="c3BlY2lhbOKAhmVtYWlsQGV4YW1wbGUuY29t"。escape("special email@example.com")给出"special%u2006email@example.com",%u2006而不是%20空间