Reputation: 5939
I have the following regular expression in Perl.
if ($line =~ m/DX/o) {
printf("%s.\n", $line);
}
if ($line =~ m/.*DX\s+.*\s+.*\s+(.*)\sGB/oi) {
printf("TRUE: %s\n", $1);
($dx = $1) =~s/,//g;
}
It is printing
DX 93,132 GB -- 2,145 GB 16840176 16835553.
But is not entering the 2nd regular expression. I have checked the regular expression and cannot see any errors. Could anyone advise?
Thanks.
Upvotes: 1
Views: 196
Reputation: 24063
If all of your fields are delimited by multiple spaces (i.e. none of the fields can contain two or more spaces in a row), I would recommend using split
instead of a regex:
if ($line =~ /^DX/) {
my @fields = split /\s{2,}/, $line;
$fields[3] =~ s/,//g; # Strip commas from 4th field
print $fields[3];
}
__END__
2145 GB
If your data is actually tab delimited, change the split
to
my @fields = split /\t/, $line;
Upvotes: 2