The "problem" is not that you can't repeat a pattern in Perl, but that only the last captures are kept for explicit (...) groups.
One way is a code section to store the current capture groups.
Another to create explicit captures.
DB<25> $_='1016.1 7.7 NaN -20.6 3.8 72.9 215.0' DB<26> $pat = qr(NaN|-?\d+\.\d) DB<27> x m/($pat)/g 0 1016.1 1 7.7 2 'NaN' 3 '-20.6' 4 3.8 5 72.9 6 215.0 DB<28> x m/($pat)(?:\s|$)/g 0 1016.1 1 7.7 2 'NaN' 3 '-20.6' 4 3.8 5 72.9 6 215.0 DB<29> x (m/($pat)(?:\s|$)/g)[0..3] 0 1016.1 1 7.7 2 'NaN' 3 '-20.6' ... DB<33> x m/(?:($pat)(?:\s|$)){4}/ 0 '-20.6' DB<34> x m/(?:($pat)(?:\s|$)(?{push @a,$1})){4}/ 0 '-20.6' DB<35> x @a 0 1016.1 1 7.7 2 'NaN' 3 '-20.6' DB<36> ... DB<47> $delim = '(?:\s|$)' DB<48> p $explicit= "($pat)$delim" x 4 ((?^u:NaN|-?\d+\.\d))(?:\s|$)((?^u:NaN|-?\d+\.\d))(?:\s|$)((?^u:NaN|-? +\d+\.\d))(?:\s|$)((?^u:NaN|-?\d+\.\d))(?:\s|$) DB<49> x m/$explicit/g 0 1016.1 1 7.7 2 'NaN' 3 '-20.6' DB<50>
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In reply to Re: Repeating a capture group pattern within a pattern
by LanX
in thread Repeating a capture group pattern within a pattern
by mldvx4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |