擅长:python、mysql、java
<p>使用<a href="http://docs.python.org/library/fnmatch.html" rel="noreferrer">^{<cd1>}</a>:</p>
<pre><code>import fnmatch
lst = ['this','is','just','a','test']
filtered = fnmatch.filter(lst, 'th?s')
</code></pre>
<p>如果要允许<code>_</code>作为通配符,只需<a href="http://docs.python.org/library/stdtypes.html#str.replace" rel="noreferrer">replace</a>所有带<code>'?'</code>(一个字符)或<code>*</code>(多个字符)的下划线。</p>
<p>如果希望用户使用更强大的筛选选项,请考虑允许他们使用<a href="http://docs.python.org/library/re.html" rel="noreferrer">regular expressions</a>。</p>