Python fnmatch negative match does not behave as expected
Question: trying to match the strings that does not containt "foo" or "bar".

After many reserch I came up with something that works with in linux `kiki`
(which is ironically written in python) but does not work when I use it in
python:

    
    
    Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
    [GCC 4.8.1] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import fnmatch, re
    >>> regex = fnmatch.translate("\Abla.bla.bla-((?!foo|bar).)*\Z")
    >>> reobj = re.compile(regex)
    >>> reobj.match('bla.bla.bla-9.9.9-123.tar.gz')
    >>> reobj.match('bla.bla.bla-9.9.9-123.foo.tar.gz')
    >>> reobj.match('bla.bla.bla-9.9.9-123.bar.tar.gz')
    

I would have expected the first occurence of reobj.match to return a positive
match.

Please help me find where I messed up.

Thanks


Answer: The pattern you specify here:

    
    
        _regex = fnmatch.translate("\Abla.bla.bla-((?!foo|bar).)*\Z"_
    

is a _regular expression_ pattern, not a shell-style
[fnmatch](https://docs.python.org/2/library/fnmatch.html) pattern. fnmatch, of
course, only understands the latter.

Shell-style matching is rather limited. To do what you want, I'd perhaps just
use a regular expression, or strip the `"bla.bla.bla-"` prefix off of the
filename and then check that `"foo" not in stripped_filename` and `"bar" not
in stripped_filename`.

