我想从日志文件中提取一些模式,但我无法正确打印它们。日志串Perl正则表达式 - 打印匹配的条件正则表达式
实例:
1) sequence_history/buckets/FPJ.INV_DOM_16_PRD.47269.2644?startid=2644000&endid=2644666
2) sequence_history/buckets/FPJ.INV_DOM_16_PRD.41987.9616
我想提取3两件事:
A = “FPJ.INV_DOM_16_PRD” B = “47269” C = 9616或2644666(如果行 已endID所然后C = 2644666否则它是9616)
日志行可以是类型1或2。我能够提取甲乙但我坚持C作为我需要的有条件的声明,我无法正确提取它。我粘贴我的代码:
my $string='/sequence_history/buckets/FPJ.INV_DOM_16_PRD.47269.2644?startid=2644000&endid=2644666';
if ($string =~ /sequence_history\/buckets\/(.*)/){
my $line = $1;
print "$line\n";
if($line =~ /(FPJ.*PRD)\.(\d*)\./){
my $topic_type_string = $1;
my $topic_id = $2;
print "$1\n$2\n";
}
if($string =~ /(?(?=endid=)\d*$)/){
# how to print match pattern here?
print "match\n";
}
在此先感谢!
就像这样https://regex101.com/r/T6QDMh/1/? – revo