import glob
list = glob.glob(r\'*abc*.txt\') + glob.glob(r\'*123*.txt\') + glob.glob(r\'*a1b*.txt\')
for i in list:
print i
This code works to
Here is a ready to use way of doing this, based on the other answers. It's not the most performance critical, but it works as described;
def reglob(path, exp, invert=False):
"""glob.glob() style searching which uses regex
:param exp: Regex expression for filename
:param invert: Invert match to non matching files
"""
m = re.compile(exp)
if invert is False:
res = [f for f in os.listdir(path) if m.search(f)]
else:
res = [f for f in os.listdir(path) if not m.search(f)]
res = map(lambda x: "%s/%s" % ( path, x, ), res)
return res