描述
此表达式将提取文件名、文件路径和当前文件夹的父路径。
((.*[\/])[^\/]*[\/])([^\/]*?)[.]bam
(
开始捕获组 1
(
开始捕获组 2
.*[\/]
贪婪匹配整个字符串直到...
)
关闭捕获组 2
[^\/]*[\/]
需要当前目录
)
关闭捕获组 1
(
开始捕获组 3
[^\/]*?
非贪婪匹配/
之前的所有非字符...
)
关闭捕获组 3
[.]
需要点字符
bam
需要 bam 值
团体
第 0 组获取整个字符串
- 获取当前路径
- 获取此文件夹的父级
- 获取带
.bam
扩展名的文件名
例子
我不太了解 python,所以这里有一个 PHP 示例来展示这个正则表达式是如何工作的。
$sourcestring="/ParentFolder1/SubFolder1/FileFoobar1.bam
/Some/Really/Deep/Folder/ParentFolder2/SubFolder2/FileFoobar2.bam";
preg_match_all('/((.*[\/])[^\/]*[\/])([^\/]*?)[.]bam/im',$sourcestring,$matches);
echo "<pre>".print_r($matches,true);
$matches Array:
(
[0] => Array
(
[0] => /ParentFolder1/SubFolder1/FileFoobar1.bam
[1] => /Some/Really/Deep/Folder/ParentFolder2/SubFolder2/FileFoobar2.bam
)
[1] => Array
(
[0] => /ParentFolder1/SubFolder1/
[1] => /Some/Really/Deep/Folder/ParentFolder2/SubFolder2/
)
[2] => Array
(
[0] => /ParentFolder1/
[1] => /Some/Really/Deep/Folder/ParentFolder2/
)
[3] => Array
(
[0] => FileFoobar1
[1] => FileFoobar2
)
)