Ok, it looks like the for-loop business is just some bug that got fixed between (my) version 5.14.4.1 and (your) version 5.20.

As to the difference between
    (b.(?{ push @two, $2 if defined $2 }))+
and
    (?: (b.) (?{ push @two, $2 }))+

It seems to me that in the first expression, the location of the  (?{ ... }) sub-expression within the second capture group means that on the first occasion that  b. can match within string, the capture group has not actually "closed" yet, and so  $2 is undefined. On each subsequent occasion, the previous capture to  $2 is what gets pushed to the array. So, the  @two array is always "one behind" in its contents if the first (undefined) value of  $2 is excluded.

In the second expression, the second capture group is always fully closed at the moment it is pushed to the  @two array, so no weirdness.


Give a man a fish:  <%-{-{-{-<


In reply to Re^6: Regex troubles... by AnomalousMonk
in thread Regex troubles... by kepler

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.