I've need to create regular expression using existing pattern. In my task user enters filename and pattern, my function should return True
in case they are compatible and False
if not.
For example, if filename='log1.txt'
, and pattern='log?.txt'
it should return True
.
So I tried to use new variable and replace method (PT = pattern.replace('?', '\w')
) to collect needed RE and return bool(re.fullmatch(pt, filename))
after that, but replace method gives me '\\w'
instead '\w'
. I tried several ways but no luck.