如何從下面的字符串獲取c999752_ABC_PAT?如何獲得模式的第一個匹配項?
$file = q(M:\c999752_ABC_PAT\Informatica_AVOB\ABC_infa\dummy\TestDeliver.txt);
如何從下面的字符串獲取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
捕獲數據
非常感謝! – user1288329
或者使用什麼Eammon建議:
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";
明顯的第一 - 你就不能按「\」爆炸? – Eamonn
我用這個:=〜/(M\:\\.+)\\/;它給了我這個:M:\ ccadm01_QRF_DEV \ Informatica_QVOB \ QRF_infa,但我只想c999752_ABC_PAT或M:\ c999752_ABC_PAT – user1288329