python mongodb正则表达式: ignore case

标签 python regex mongodb

如何指定一个正则表达式并忽略大小写:

regex = ".*" + filter + ".*";
config.gThingCollection.find({"name":{"$regex":regex}})

我希望过滤器不区分大小写,如何实现?

最佳答案

尝试改用 python 正则表达式对象。 Pymongo 会正确序列化它们:

import re
config.gThingCollection.find({"name": re.compile(regex, re.IGNORECASE)})

关于python mongodb正则表达式: ignore case,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4976278/

相关文章:

python - 使用 REGEX 匹配 Python 中行之间的元素

python - Selenium 网络驱动程序 : how do respond on a prompt

python - 当我在 MongoDB 中进行地理空间查询时,如何返回距所需点的距离?

mongodb - 从MongoDB到ElasticSearch的地理位置

java - 正则表达式,引号之间的值

html - 呈现 HTML 格式的 mongo 文档

python - 将部分 H :M:S durations with missing parts, 转换为秒;或右对齐非 NA 数据

python - Pandas 字符串标记化太慢

c# - 从字符串源列表动态生成最短正则表达式

javascript - 匹配字符串中带有小数分隔符的数字