in reply to Re: positions of all regexp matches
in thread positions of all regexp matches
I can imagine this explanation is a bit abstract, so I'll give a different example. Here I'm trying to match an uppercase letter that is the first of a sequence of at least 3 letters, including itself.
Resulting in:$_ = 'Ab1Cd2eFg3Hijk4LMN'; /((?=([a-zA-Z]{3,}))[A-Z])/ or die "No match"; print <<"END"; Whole match: \$&: '$&' $-[0] upto $+[0] Parens around everything matched: \$1: '$1' $-[1] upto $+[1] Lookahead matched: \$2: '$2' $-[2] upto $+[2] END
Whole match: $&: 'H' 10 upto 11 Parens around everything matched: $1: 'H' 10 upto 11 Lookahead matched: $2: 'Hijk' 10 upto 14
As you can see, the parens around everything matched the same as the whole match itself. The lookahead extends beyond that, and even though you can capture what it matched, it doesn't count for the length. The first thing after the lookahead is still the same thing as the first thing of the whole match.
|
|---|