I am trying to list only specified files in my directory but getting only empty results. When I checked the expected results with regex tester (https://regex101.com/), I've got the expected results.
But in the python code, I can see nothing.
I tried some other combinations in regex string but nothing helped. I can list the whole directory though.
Am I doing something wrong ? It looks like quite simple solution so what am I missing ?
Code here:
import os
import fnmatch
directory = 'output/'
for filename in os.listdir(directory):
if fnmatch.fnmatch(filename, '^[20]+[0-9]+\.xlsx$'):
print(filename)
Can you please have a look and give me some hint ?
Many thanks