如何在python中搜索字符串中的值,并且仅在该字符串不包含搜索字符串中的任何前导/滞后值时返回。白间距是可接受的,即
我想在下面有子文件夹的文件夹中搜索“WO1”或“WO1 BLD2 L1 H3 Fitout”
子文件夹:
WO1
WO123SP10152100 WO137
WO1 BLD2 L1 H3 Fitout
我使用的代码返回“SP10152100 WO137”
temp_WO_dir1 = "WO" + wo
path = root + "\\"+ dir
for root, dirs, files in os.walk(path):
for dir in dirs:
print dir
if temp_WO_dir1 in dir:
find = True
sp_path = root + "\\" + dir + "\\3 Finance\\Telstra Invoicing"
print sp_path
break
if root.count(os.sep) - path.count(os.sep) == 0:
del dirs[:]
更新:
尝试了以下操作但不起作用
if re.match(temp_WO_dir1+"\s" , dir):
WO1
旁边是单词boundry,后面是anything,后面是anything.*\bWO1\b.*
相关问题 更多 >
编程相关推荐