Is there a simple way to support wildcards (‘*’) when searching strings – without using RegEx?
Users are supposed to enter search terms using wildcards, but should not have to deal with the complexity of RegEx:
'foo*' => str.startswith('foo') '*foo' => str.endswith('foo') '*foo*' => 'foo' in str
(it gets more complicated when there are multiple search terms though, e.g. ‘foobarbaz’)
This seems like a common issue, so I wonder whether there’s a ready-made solution for it.
Any help would be greatly appreciated!
You could try the
fnmatchmodule, it’s got a shell-like wildcard syntax.