my $path= "/tmp/main/store/important/file/log"; ##string
$path =~ m/file/;
print "$&/$'\n";
我想捕捉 file/log/.*/.*/ .. . . ..
路径可能会有所不同,还有其他方法可以解决这个问题吗?
谢谢你们
只需使用贪婪匹配 ( .*
):
my $path= "/tmp/main/store/important/file/log";
my ($tail) = $path =~ m!(/file/.*)!;
print $tail; # /file/log
在这里,我还为m//
运算符使用了自定义分隔符,以避免转义斜杠。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句