How to match a string against a set of wildcard strings efficiently?
<p>I am looking for a solution to match a single string against a set of wildcard strings. For example</p>

<pre><code>&gt;&gt;&gt; match("ab", ["a*", "b*", "*", "c", "*b"])
["a*", "*", "*b"]
</code></pre>

<p>The order of the output is of no importance.</p>

<p>I will have in the order of 10^4 wildcard strings to match against and I will do around ~10^9 match calls. This means I will probably have to rewrite my code like so:</p>

<pre><code>&gt;&gt;&gt; matcher = prepare(["a*", "b*", "*", "c", "*b"]
&gt;&gt;&gt; for line in lines: yield matcher.match("ab")
["a*", "*", "*b"]
</code></pre>

<p>I've started writing a trie implementation in Python that handles wildcards and I just need to get those corner cases right. Despite this I am curious to hear; <strong>How would you solve this? Are there any Python libraries out there that make me solve this faster?</strong></p>

<p>Some insights so far:</p>

<ul>
<li>Named (Python, re) regular expressions will not help me here since they'll only return one match.</li>
<li><a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a> seems like an awesome library, but is sparsely documented and does not, as I see it, support matching multiple patterns.</li>
</ul>
