I'm not sure if this is real bug, but the documentation of fnmatch.translate states: fnmatch.translate(pattern) Return the shell-style pattern converted to a regular expression. My intuition about shell-style pattern is that for example, pattern:t3 should match only t3, and not ost3 or xxxxxt3, but what I receive from fnmatch is: In [2]: fnmatch.translate("t3") Out[2]: 't3\\Z(?ms)' so using for example re.search will match not only on t3, but also on xxxt3 (in shell-like pattern is *t3). So... I believe it should be changed or at least the documentation should be more specific about what "shell-style pattern" mean.
it can be changed easyly with changing the return statement in fnmatch.py function translate from: return res + '\Z(?ms)' to: return '^' + res + '\Z(?ms)'
The result of fnmatch.translate() is used with re.match(). It could be even simplified if use it with re.fullmatch(), but I afraid such change can break user code.
So you suggest that this output should not be used with re.search ? Why? I think it should be documented, or maybe it is? I know that this is not possible to introduce such a change to the currently used versions.