我正在嘗試在陣列中捕獲命名組。
use strict;
use warnings;
use Data::Dumper;
my $text = 'My aunt is on vacation and eating some apples and banana';
$text =~ m/(?<Letter>A.)/img ;
print Dumper(%-) ;
輸出是
$VAR1 = 'Letter';
$VAR2 = [
'au'
];
但我希望或實際上希望任何事件都會出現在陣列中。
$VAR1 = 'Letter';
$VAR2 = [
'au',
'ac',
'at',
'an',
'at',
'an'
];
有機會將所有組放在一個陣列中嗎?
uj5u.com熱心網友回復:
您可以運行m//gin list 背景關系以獲取所有匹配的子字串(但沒有捕獲名稱),或者您需要在回圈中匹配:
my @matches = $text =~ m/(?<Letter>A.)/img ;
print Dumper(\@matches) ;
或者
while ($text =~ m/(?<Letter>A.)/img) {
print Dumper(\% ) ;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/513184.html
標籤:正则表达式perl
上一篇:如何使數字警告致命?
