Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
meh solution in Clear category for Unix Match. Part 1 by ssk8
def unix_match(filename: str, pattern: str) -> bool:
file_match, pos, ast = '', [0], False
for sym in pattern:
if pos[-1] >= len(filename): return False
if ast and sym != '*':
pos.append(filename.find(sym, pos[-1]))
if pos[-1] == -1: return False
file_match += filename[pos[-2]:pos[-1]]
ast = False
if sym == '*':
ast = True
elif sym == '?':
pos.append(pos[-1]+1)
file_match += filename[pos[-2]]
else:
pos.append(pos[-1]+1)
file_match += sym
else:
if ast:
file_match += filename[pos[-1]:]
return filename == file_match
July 13, 2018
Comments: