Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Unix Match. Part 2 by jiangyang
import re
def unix_match(filename: str, pattern: str) -> bool:
# your code here
pattern = pattern.replace('!','^').replace('[^]','\[!\]').replace('[]','\[\]')
return bool(re.match(pattern,filename))
print("Example:")
print(unix_match("log1.txt", "log[!1].txt"))
# These "asserts" are used for self-checking
assert unix_match("log1.txt", "log[1234567890].txt") == True
assert unix_match("log1.txt", "log[!1].txt") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 9, 2023
Comments: