in reply to Re^5: Regex troubles...
in thread Regex troubles...

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:  <%-{-{-{-<