Matching a glob against another glob

OK, it is my time to ask something :wink:

Is there a module in Python that can match globs to themselves?
For example: if I have got “*.txt” and “*.t??” then, in my mind, they match because any filename that the first pattern matches the second pattern matches too. But not the other way.

I think what you’d want to do is first use fnmatch.translate() to convert them to a regular expression. Then, this Stack Overflow question has some guidance on how to do it for those. Or this other answer describes how to do it directly.

1 Like

Thanks a lot sir! I think I will go with the second link’s example. The only thing I wish to know is how that’s working, because now I can only copy-paste the code and :pray: it works for all cases >_>