I am trying to write a function to return all occurrences of a substring that contains wildcards (each wildcard accounting for only one character) within a longer string.
For instance, let's say I have the subject string:
aabcddcabaabedcbabaa
and my query string is b?d??ab
.
The expected output would be:
['bcddcab', 'bedcbab']
Looking through other stack overflow posts, I've tried the following:
import fnmatch
subject = "aabcddcabaabedcbabaa"
query = "b?d??ab"
res = fnmatch.filter(subject, query)
but this returns an empty list. What am I doing wrong? Am I actually using the filter
function of fnmatch
correctly? Thank you in advance