Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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中创建以不同目录名开头的正则表达式_Python_Regex - Fatal编程技术网

如何在Python中创建以不同目录名开头的正则表达式

如何在Python中创建以不同目录名开头的正则表达式,python,regex,Python,Regex,目前,我将目录路径作为用户的输入。每个用户的路径将不同(目录名称将不同) 而dir_name中的结构对于所有用户都是相同的,如下所示: tar1 tar2 tar3 tar4 tar5 tar6 source 在每个tar中,有三个文件夹:build-collateral-fix 附带资料:我有三个不同的文件 _base.txt, _fullbase.txt and _skip.txt 我还需要source/projectfiles/params/tar_base.dot | tar_f

目前,我将目录路径作为用户的输入。每个用户的路径将不同(目录名称将不同)

而dir_name中的结构对于所有用户都是相同的,如下所示:

tar1 tar2 tar3 tar4 tar5 tar6 source
在每个tar中,有三个文件夹:
build-collateral-fix
附带资料:我有三个不同的文件

 _base.txt, _fullbase.txt and _skip.txt 
我还需要
source/projectfiles/params/tar_base.dot | tar_fullbase.dot | tar_skip.dot

以下是我需要做的:
1.从用户处获取输入 2.一个接一个-进入目标。(tar1->tar2->tar3->tar4->tar5) 3.对于每个tar,搜索辅助文件夹 4.并在附属文件夹中搜索所有三个.txt文件 5.对于每个.txt文件,搜索相应的.dot文件

目前我做了以下工作: 我从用户处获取txt的路径

txtfilepath = raw_input (" Please provide file path for the desired txt")
dotfilepath = raw_input (" Please enter corresponding .dotfilepath")
<directory path>/<tar1>/collateral/<xyz_base.txt)
txtfilepath=raw\u输入(“请提供所需txt的文件路径”)
dotfilepath=原始输入(“请输入相应的.dotfilepath”)

//抵押品/听起来不适合正则表达式。使用
os.path.split
逐个处理它。对于问题本身,使用shell ScriptingHanks应该更容易处理。我也许应该研究一下操作系统模块。@hustmphrr:谢谢你的建议。我解决了这个问题。
txtfilepath = raw_input (" Please provide file path for the desired txt")
dotfilepath = raw_input (" Please enter corresponding .dotfilepath")
<directory path>/<tar1>/collateral/<xyz_base.txt)
platform = re.search("?<=/collateral/).(?="_(base|fullbase|skip)\.txt)",txtfilepath).group(0)