>我试图匹配以下行
5474c2ef012a759a c11ab88ae8daa276 63693b53799c91f1 be1d8c8738733d80
跟
if(/[[:xdigit:]{8}[:xdigit:]{8}s]{4}/)
无论如何,我用每个单词的一半填充自动变量 $1,$2,$3..$8 等。即
$1=5474c2ef
$2=012a759a
$3=c11ab88a
$4=e8daa276
$5=63693b53
$6=799c91f1
$7=be1d8c87
$8=38733d80
您可以在数组中捕获它们:
use strict;
use warnings;
use Data::Dumper;
$_ = '5474c2ef012a759a c11ab88ae8daa276 63693b53799c91f1 be1d8c8738733d80 ';
my @nums = /G(?:([[:xdigit:]]{8})([[:xdigit:]]{8})s)/g;
if (@nums >= 8) {
print Dumper(@nums);
}
(如果有超过四个,或者如果早期的 16 位十六进制序列之间隔开的不仅仅是一个空格,则行为可能与原始序列不同)。
怎么样:
my $pat = '([[:xdigit:]]{8})s?' x 8;
# produces: ([[:xdigit:]]{8})s?([[:xdigit:]]{8})s?....
/$pat/;
如果需要严格要求间距要求,请更新:
my $pat = join('s', map{'([[:xdigit:]]{8})' x 2} (1..4));
# produces: ([[:xdigit:]]{8})([[:xdigit:]]{8})s....
/$pat/;
use strict;
use warnings;
use Data::Dumper;
$_ = '5474c2ef012a759a c11ab88ae8daa276 63693b53799c91f1 be1d8c8738733d80 ';
if (/((?:[[:xdigit:]]{16}s){4})/) {
my @nums = map { /(.{8})(.{8})/ } split /s/, $1;
print Dumper(@nums);
}
__END__
$VAR1 = [
'5474c2ef',
'012a759a',
'c11ab88a',
'e8daa276',
'63693b53',
'799c91f1',
'be1d8c87',
'38733d80'
];
是的,有,但你不想。
你只想这样做:
while ( /(p{ahex}{8})/g ) { print "got $1n" }