gpt4 book ai didi

python mongodb正则表达式: ignore case

转载 作者:IT老高 更新时间:2023-10-28 13:07:58 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com