Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Unix Match. Part 3 by Moff
import re
def unix_match(filename: str, pattern: str) -> bool:
re_pattern = pattern
for a, b in [('.', '\.'), ('*', '.*'), ('?', '.'), ('[!', '[^'),
('[[]', '\['), ('[]]', '\]'), ('[.]', '\?'), ('[.*]', '\*')]:
re_pattern = re_pattern.replace(a, b)
try:
return re.match(re_pattern, filename) is not None
except:
return filename == pattern
Feb. 27, 2018
Comments: