Since the matched
$1 is located at the beginning of the matched substring,
$-[0] (left of whole match) and
$-[1] (left of
$1) have the same value. However, since the lookahead assertion doesn't count in the total width, the whole matched string thus has length zero,
$+[0] == $-[0], while
$1 inside the lookahead extends further to the right, thus
$+[1] > $-[1].
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.
$_ = '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
Resulting in:
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.