in reply to Repeating a capture group pattern within a pattern
This might be cheating, but when retrieving multiple repeated matches, I often use /g after validating that the line looks somewhat valid:
my $re4 = qr/\b([Na0-9\.\-\+]+)\b/; # capture a floating point number my @vals = ($x =~ m/$re4/gx ); croak "Invalid line '$x'" if @vals != 4; ($d, $e, $f, $g) = @vals;
Often, I first identify the section without capturing and then parse it in a second step (but that's not what you wanted):
my $float = qr/\b([Na0-9\.\-\+]+)\b/; croak "Invalid line '$x'" if $x !~ /((?:$float(\s+|$)){4}))/; print "Found numbers '$1'\n"; my @vals = $1 =~ /($float)/g;
I did not find a way to capture the repeated values in one go.
|
---|