最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Discord bot wild card in filename - Stack Overflow

programmeradmin2浏览0评论

i have a bot that search images through filename. for now it searches only for exact sring. like if i type -s house_art it will search for only house_art in filenname. not for house_xyyzt_art etc. is there a way to achieve wild string like if type house%art where % represents any string like house_yuyuy_art,house__art.

here is current way ti search

required_keywords.add(keyword.lower())
has_required_keywords = all(keyword in filename for keyword in required_keywords)

i have tried these way but it would return 0 return only in case of %

pattern = keyword.replace('%', '.*')
required_keywords.add(pattern.lower())

has_required_keywords = all(keyword.search(filename) if isinstance(keyword, re.Pattern) else keyword in filename for keyword in required_keywords)
发布评论

评论列表(0)

  1. 暂无评论