simplifies to ^

Oh... I didn't understand the whole construct, then. Thanks! I guess "Possessive sub-pattern with non-greedy..., etc." can be stricken out from title. To be replaced with, start-of-string anchor and failure? Because,

Match fails -- it's irrelevant

But looks like it is. And, in parallel, comparing with look-ahead, which at 1st glance can be a simpler alternative (?):

say $-[1], ': ', $1 while 'olololo' =~ / (?= ( (.)(?-2)\g-1 | (.).\g-1 ) ) /gx; say '*'; say 'match' if 'olololo' =~ / ^ ( ( (.)(?-3)\g-1 | (.).\g-1 ) (?{ say $-[2], ': ', $2 }) ) (?#*F) /x;

Output:

0: olololo 1: lolol 2: ololo 3: lol 4: olo * 4: olo 3: lol 2: ololo 2: olo 1: lolol 0: olololo match

Look-ahead misses some PD's for obvious reasons. But match success in case of recursion leads to omission of 2 PD's, too. Why? Converting "comment" to "fail" i.e. (F*) gives all nine PD's, visited exactly once each (with some disruption to "visit in reverse" order):

4: olo 3: lol 2: ololo 2: olo 1: lolol 0: olololo 1: lol 0: ololo 0: olo

In reply to Re^2: Possessive sub-pattern with non-greedy content + recursion: WHY does this work?? by Anonymous Monk
in thread Possessive sub-pattern with non-greedy content + recursion: WHY does this work?? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.