Take the 2-minute tour ×

Basically I want to screen for the following files in python using glob.glob module:


but excluding:


Naively played around with linux wildcard (eg log_*[!_]* but apparently not working). How can I use inverse or negative wildcards when pattern matching in a unix/linux shell? seems not helping, and thanks for advices!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You are close. The pattern you are looking for is log_[^_]*. It says it must have 'log_' followed by zero or more non-underscore characters.

share|improve this answer
Actually this didn't work. The files I am looking for is "log_" following by some characters, in which there are no more underscores. The wildcard "log_[^_]*" only refers to the file names starting from "log_" and not directly followed by another "_". –  Hailiang Zhang Jan 29 '13 at 21:17
@HailiangZhang I missed you are using glob. The above is regex. I think the answer is you aren't going to be able to do it with glob. Glob is very limited, specifically it does not allow you to specify a repeating pattern. I would get the results from os.listdir and use the regex above for filtering. –  iagreen Jan 29 '13 at 21:39

you are using the wrong character to say none of this character...

If you're looking to find any file which has log_ at the beginning, and then a load of characters where none of them are _, then you just need to do this:


share|improve this answer

Your Answer


