Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write "or" in a glob() pattern?

Tags:

python

glob

glob.glob() does not use regex. it uses Unix path expansion rules. How can I emulate this regex in glob:

".*.jpg|.*.png"
like image 349
alzoubi36 Avatar asked Nov 17 '25 03:11

alzoubi36


1 Answers

Well, with glob you should just do this:

lst = glob.glob('*.jpg') + glob.glob('*.png')
like image 124
U12-Forward Avatar answered Nov 18 '25 16:11

U12-Forward