Again from perlvar:
One can use $#- to find the last matched subgroup in the last successful match. Contrast with $#+, the number of subgroups in the regular expression.
Some code that might or not result in what you want (as I am still not sure where you are going with this.)
use strict; use warnings; local $\ = $/; my $text = "abc123def"; my $text_match = qr/((\D+)(?{ print $#- })(\d+)(\d+))/; $text =~ $text_match; $text_match = qr/(\D+)(?{ print $#- })(\d+)(\d+)/; $text =~ $text_match; $text_match = qr/((\D+)(\d+)(\d+))(?{ print $#- })/; $text =~ $text_match; $text_match = qr/((\D+)(\d+)(\d+)?(?{ print $#- }))/; $text =~ $text_match; $text_match= qr/((\D+)((\d+)(\d+)))(?{ print $#- })/; $text =~ $text_match; __END__ 2 1 4 3 5
-enlil
In reply to Re: Finding the right $<*digit*> capture variable
by Enlil
in thread Finding the right $<*digit*> capture variable
by diotalevi
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |