擅长:python、mysql、java
<p>在您的情况下,<code>regex</code>不是真正必要的,如果您想删除文件名中包含任何数字的任何文件,那么您可以通过以下方式简单地执行此操作:</p>
<pre><code>import os
my_path = 'path_to_your_directory'
any_digit = '1234567890'
os.chdir(my_path) #Just to be sure you are in your working directory not else where!
for f in os.listdir('.'):
if any(x in f for x in any_digit) and f.endswith('.jpg'):
os.remove(f)
</code></pre>
<p>您也可以使用<code>string</code>模块,然后:</p>
^{pr2}$