【发布时间】:2021-02-02 13:50:43
【问题描述】:
我想提取(使用 perl)xxx(块之后的字符串:)和 prod(里程碑之后的字符串:)。字符串(在 Block: 和 Milestone: 之后)和空格数不是标准的。我只能使用底部命令 grep 整行:
use strict;
use warnings;
my $file = 'xxx.txt';
open my $fh, '<', $file or die "Could not open '$file' $!\n";
while (my $line = <$fh>){
chomp $line;
# my @stage_status = $line =~ /(\:.*)\s*$/;
my @stage_status = $line =~ /\b(Block)(\W+)(\w+)/;
foreach my $stage_statuss (@stage_status){
print "$stage_statuss\n";
}
}
文件中的行示例:
| Block: | xxx | Milestone: | prod |
【问题讨论】:
-
根据下面的 cmets OP 正在 Perl/Grep 中尝试此代码并需要正则表达式帮助,因此它是相关标签。