[Python] Discord bot wild card in filename

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    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)

    Continue reading...

Compartilhe esta Página