1

如何从下面的字符串中获取 c999752_ABC_PAT?

$file = q(M:\c999752_ABC_PAT\Informatica_AVOB\ABC_infa\dummy\TestDeliver.txt);
4

3 回答 3

1

你可以使用这个正则表达式

^.*?\\(.*?)\\.*$
|   |   |     |->matches till the end
|   |   |->your content matched till the first occurance of \
|   |->match lazily till the first \
|->start of the text

Group1捕获您的数据

于 2012-11-04T16:26:18.360 回答
1

Or use what Eammon suggested:

my $firstPart = ( split /\\/, $file )[1];
于 2012-11-04T16:30:45.723 回答
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";
于 2012-11-04T18:22:23.393 回答