Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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/8/perl/9.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
Regex 从路径捕获子目录_Regex_Perl - Fatal编程技术网

Regex 从路径捕获子目录

Regex 从路径捕获子目录,regex,perl,Regex,Perl,我想捕获文件/log/*/.*/ 路径可能会有所不同,还有其他解决方法吗 谢谢大家只要使用贪婪匹配(*): 这里我还为m/操作符使用了一个自定义分隔符,以避免斜杠转义。只需使用贪婪匹配(*): 这里我还为m/操作符使用了一个自定义分隔符,以避免斜杠转义 my $path= "/tmp/main/store/important/file/log"; ##string $path =~ m/file/; print "$&/$'\n"; my $path= "/tmp/main/sto

我想捕获
文件/log/*/.*/

路径可能会有所不同,还有其他解决方法吗

谢谢大家

只要使用贪婪匹配(
*
):

这里我还为
m/
操作符使用了一个自定义分隔符,以避免斜杠转义。

只需使用贪婪匹配(
*
):

这里我还为
m/
操作符使用了一个自定义分隔符,以避免斜杠转义

my $path= "/tmp/main/store/important/file/log"; ##string

$path =~ m/file/;

print "$&/$'\n";
my $path= "/tmp/main/store/important/file/log";
my ($tail) = $path =~ m!(/file/.*)!;
print $tail;  # /file/log