def find_matching_files(directory, regex):
 files = glob.glob(os.path.join(directory, '*'))
 results = []
 for f in files:
  if regex.match(os.path.basename(f)):
   results.append(f)
 return results

def find_matching_files ( directory , regex ) : files = glob . glob ( os . path . join ( directory , '*' ) ) results = [ ] for f in files : if regex . match ( os . path . basename ( f ) ) : results . append ( f ) return results
find all files in a given directory that match a given regex .