fork download
  1. import re
  2.  
  3. def repl(m):
  4. res = "{}{}".format(re.escape(m.group(1)), m.group(2).replace("*", ".*").replace("?", "."))
  5. if m.group(3):
  6. res += re.escape(m.group(3))
  7. return res
  8.  
  9. def glob_to_regex(glob):
  10. glob = re.sub(r'\*{2,}', '*', glob)
  11. return '(?s)' + re.sub(r'([^?*]*)([*?]+)([^?*]+$)?', repl , glob)
  12.  
  13. l = ['baab', 'abbb', 'fc', 'AA', 'abb.']
  14. print([x for x in l if re.search(glob_to_regex('?b*b'), x)])
  15. print([x for x in l if re.search(glob_to_regex('?b*.'), x)])
Success #stdin #stdout 0.02s 9648KB
stdin
Standard input is empty
stdout
['abbb', 'abb.']
['abb.']