Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当windows无法创建已存在的文件时,正则表达式列表文件_Python_Regex - Fatal编程技术网

Python 当windows无法创建已存在的文件时,正则表达式列表文件

Python 当windows无法创建已存在的文件时,正则表达式列表文件,python,regex,Python,Regex,基本上,我只想列出那些windows不会创建的文件。 我如何列出4.txt和4a.txt来代替s==s是否为真 myList = ''' 4.txt 4a.txt spam ''' myregex = 'a' s = re.sub(myregex,'',myList) if s == s: print "got it!" # prints 'got it' print s == s # prints 'true' 代码: 输出: =============

基本上,我只想列出那些windows不会创建的文件。 我如何列出4.txt和4a.txt来代替
s==s
是否为真

myList = '''
4.txt
4a.txt
spam
'''
myregex = 'a' 
s = re.sub(myregex,'',myList)

if s == s:    
    print "got it!"  # prints 'got it'
    print s == s     # prints 'true'
代码:

输出:

=================================================重新启动================================

4.txt matches 4\w?\.txt
4.txt matches 4.*\.txt
4.txt matches \d\w?\.txt
4a.txt matches 4\w?\.txt
4a.txt matches 4.*\.txt
4a.txt matches \d\w?\.txt
spam does not match 4\w?\.txt
spam does not match 4.*\.txt
spam does not match \d\w?\.txt

您不需要正则表达式来完成此操作。
只需使用
os.path.exists

import os
lst = [your_fileNames....]

for arch in lst:
    if not os.path.exists(arch):
        print arch

你应该把这篇文章贴上python的标签。我不明白你的问题。你似乎误解了很多事情。为什么把
s==s
放在那里,它的计算结果总是
True
import os
lst = [your_fileNames....]

for arch in lst:
    if not os.path.exists(arch):
        print arch