如何从下面的字符串中获取c999752_ABC_PAT?
$file = q(M:\c999752_ABC_PAT\Informatica_AVOB\ABC_infa\dummy\TestDeliver.txt);
答案 0 :(得分:1)
您可以使用此正则表达式
^.*?\\(.*?)\\.*$
| | | |->matches till the end
| | |->your content matched till the first occurance of \
| |->match lazily till the first \
|->start of the text
Group1
捕获您的数据
答案 1 :(得分:1)
或者使用Eammon的建议:
my $firstPart = ( split /\\/, $file )[1];
答案 2 :(得分:0)
use File::Spec::Win32;
my $file = q(M:\c999752_ABC_PAT\Informatica_AVOB\ABC_infa\dummy\TestDeliver.txt);
my ($volume, $directories) = File::Spec::Win32->splitpath($file);
my @directories = File::Spec::Win32->splitdir($directories);
print $directories[1], "\n";