如何从下面的字符串中获取 c999752_ABC_PAT?
$file = q(M:\c999752_ABC_PAT\Informatica_AVOB\ABC_infa\dummy\TestDeliver.txt);
你可以使用这个正则表达式
^.*?\\(.*?)\\.*$
| | | |->matches till the end
| | |->your content matched till the first occurance of \
| |->match lazily till the first \
|->start of the text
Group1
捕获您的数据
Or use what Eammon suggested:
my $firstPart = ( split /\\/, $file )[1];
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";