Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Step-by-step using replace and re solution in Clear category for Unix Match. Part 1 by kkkkk
import re
def unix_match(filename: str, pattern: str) -> bool:
"""Return True if regex pattern matches string, False if not."""
if '.' in pattern:
pattern = pattern.replace('.', '\.')
if '*' in pattern:
pattern = pattern.replace('*', '.*')
if '?' in pattern:
pattern = pattern.replace('?', '.')
matches = re.match(pattern, filename)
if matches and matches.group() == filename:
return True
return False
Dec. 26, 2019
Comments: