有没有更好的方法来使用正则表达式捕获分组编写下面的代码?Perl正则表达式捕获分组
我期待在录制后立即获取文件夹名称。
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $path1 = '\\server1\Recordings\AU-AR-Online\Outbound\20160120\52031\52031-14-07-16.wav';
my $path2 = '\\server2\e$\Recordings\SU-AC-Online\Outbound\20160120\52031\52031-14-07-16.wav';
my @paths = ($path1,$path2);
foreach my $path (@paths) {
# Split path into fields
my @array = (split /\\/, $path);
# Get index of Recordings
my($index)= grep { $array[$_] eq "Recordings" } 0..$#array;
# Brand always follows Recordings
print $array[$index+1];
}