擅长:python、mysql、java
<p>python正则表达式引擎使用传统的NFA来匹配模式并不是一个bug。而字符<code>*</code>只有在前面加上标记时才起作用</p>
<blockquote>
<p><code>'*'</code></p>
<p>Causes the resulting RE to match 0 or more repetitions of the <strong>preceding</strong> RE, as many repetitions as are possible. ab* will match ‘a’, ‘ab’, or ‘a’ followed by any number of ‘b’s.</p>
</blockquote>
<p>因此,您可以使用<code>.*</code>来重复任何字符(<code>.</code>):</p>
<pre><code>r'.*([a-zA-Z]+)\.csv'
</code></pre>
<p>python还提供了支持Unix shell样式通配符的模块<a href="https://docs.python.org/2/library/fnmatch.html" rel="noreferrer">^{<cd4>}</a></p>
<pre><code>>>> import fnmatch
>>> s="/some/path/to/file/abcde.csv"
>>> fnmatch.fnmatch(s, '*.csv')
True
</code></pre>