擅长:python、mysql、java
<p>您不需要Regex来检查文件名是否以<code>.srt</code>结尾。<a href="https://docs.python.org/2/library/stdtypes.html#str.endswith" rel="noreferrer">^{<cd2>}</a>很容易做到:</p>
<pre><code>for files in curDir:
if files.endswith('.srt'): # Filename ends in .srt
...
else: # Filename does not end in .srt
...
</code></pre>
<p>只有当您有复杂的模式需要匹配时才应该使用Regex(然后,无论如何都要使用它!)。否则,应该避免使用它,因为它比Python的内置工具慢,而且对于没有经验的人来说也有些困难。在</p>