Hi all
I need to match two strings with simple wildcards:
"oh.my.*"
matches "*.my.life"
, "oh.my.goodness"
and "*.*.*"
, but not "in.my.house"
The only wildcard is *, which substitutes string of any character (minus .)
I thought of using fnmatch, but it does not accept wildcards in file name.
There is some code with regex which i am using now - something simpler would be better, i guess:
def notify(self, event, message):
events = []
r = re.compile(event.replace('.','\.').replace('*','[^\.]+'))
for e in self._events:
if r.match(e):
events.append(e)
else:
if e.find('*')>-1:
r2 = re.compile(e.replace('.','\.').replace('*','[^\.]+'))
if r2.match(event):
events.append(e)
for event in events:
for callback in self._events[event]:
callback(self, message)