How long has it been that regexes have returned
anything
predictable from non-matching parenthesis within regexes that match?
With a regex like /A(.)?B/, perl used to fill $1
with whatever the last attempt at a match was, and so the result
was not undefined, but unpredictable. So on a string like 'AB',
you'd end up with 'B' in $1, and although it might be non-intuitive,
it was actually conceptually correct, because the string does
match /A(B)?B/, and it was up to the programmer to
use something more sensible, like </code>/A((.)?)B/</code>, and
only depend on the inner parenthesis if the outer ones contain something besides
the empty string.
But now I guess perl just does (or will do) the right thing :)