【发布时间】:2019-05-05 21:50:56
【问题描述】:
我正在尝试在 Perl 中使用多个反向引用来匹配 5 种不同的模式,但除了第一个之外我没有得到任何匹配。
我尝试了以下方法:
my $string = ">abc|XYUXYU|KIOKEIK_7XNCU Happy, not-happy apple banana X ORIG=Came from trees NBMR 12345 OZ=1213379 NG=popZ AZ=2 BU=1";
$string =~ m/>(abc)|(.*)|.*ORIG=(.*)[A-Z].*NG=(.*)\s(.*)\s/;
print "First match should be 'abc'. We got: $1\n";
print "Second match should be 'XYUXYU'. We got: $2\n";
print "Third match should be 'Came from trees'. We got: $3\n";
print "Fourth match should be 'popZ'. We got: $4\n";
print "Fifth match should be 'AZ=2'. We got: $5\n";
我想作为输出:
First match should be 'abc'. We got: abc
Second match should be 'XYUXYU'. We got: XYUXYU
Third match should be 'Came from trees'. We got: Came from trees
Fourth match should be 'popZ'. We got: popZ
Fifth match should be 'AZ=2'. We got: AZ=2
任何线索如何在 Perl 上以正确的方式解决这个问题?
【问题讨论】:
-
语言名称是 Perl,而不是 PERL。这不是首字母缩写词
标签: regex perl backreference