in reply to Re: A bug in regex with conditional subpattern?
in thread A bug in regex with conditional subpattern?

and simply moves on to the next element.

And that's the bug, IMHO. If the yes-pattern is present, and the condition fails, the whole match normally fails. Why should it move on if the match fails? Compare:

'a' =~ /^xa/ # match of x fails, doesn't move on to match a

When the no-pattern is not present, and the condition fails, it normally doesn't match:

$ perl -wE 'say "a" =~ /^(?(?=b)xxx)a/' $ # no match

So it doesn't show the "move on"-behavior when the yes-pattern is something else than the empty pattern.

So it's a special case. And it's not documented. So it's a bug.

Replies are listed 'Best First'.
Re^3: A bug in regex with conditional subpattern?
by ig (Vicar) on Mar 17, 2011 at 18:00 UTC
    Why should it move on if the match fails?

    Is "(?(condition)yes-pattern)" an abbreviation for "(?(condition)yes-pattern|)" (i.e. with an explicitly empty no-pattern)? This seems most reasonable to me, but I find nothing in the documentation to suggest whether this or any other possibile behaviour should be expected.

    The most fundamental "bug" seems to be lack of documentation of intended behaviour.