我想捕获文件某些行中包含的数字。我正在使用 Perl,并且正在使用匹配运算符来捕获相对于文件行中其他符号的特定位置出现的数字。这是一个示例行:
fixedStep chrom=chr1 start=3000306 step=1
这是脚本的相关部分:
while ( <FILE> ) {
if ( $_=~m/fixedStep/ ) {
my $line = $_;
print $line;
my $position = ($line =~ /start\=(\d+)/);
print "position is $position\n\n";
}
$position
打印为1
,而不是我需要的数字。根据在线正则表达式工具 regex101.com,我使用的正则表达式有效;它捕获行中的适当元素。