0

I have three files in a folder - stage-utah, stage1-utah, stage2-utah. I use glob to get it expanded to the list. But with the regular expression stage[12]*-utah, I was expecting it will be expanded to all the files in the dir, as * matches to zero or more occurrences. But it expands to only stage1-utah and stage2-utah.

What is wrong in my expression?

>> stagedir = glob.glob("./stage*")
>> stagedir
['./stage1-utah', './stage2-utah', './stage-utah']

>> stagedir = glob.glob("./stage[12]*")
>> stagedir
['./stage1-utah', './stage2-utah']
rrauenza
  • 6,285
  • 4
  • 32
  • 57
user2647717
  • 129
  • 1
  • 9
  • 7
    You're confusing globs and regex. In globs, `*` matches 0-n of any character (equivalent to regex `.*`). Globs normally don't support what you're trying to do, though you could maybe do `stage*-utah` if that works for your case. – that other guy Jun 28 '16 at 02:54
  • You can refer this for using regex in glob.glob: http://stackoverflow.com/questions/13031989/regular-expression-using-in-glob-glob-of-python – Siva Arunachalam Jun 28 '16 at 02:55

0 Answers0