It sure seems like a bug to me.

Yes, I've reached the same conclusion after having played around with this some more.

The issue can be reduced to the following simple test case:

use re 'Debug' => "EXECUTE"; say "xb" =~ /^(?(?!a) (?=bb)).b$/x ? "yes":"no"; # -> yes (wrong +) say "xb" =~ /^(?(?!a) (?{}) (?=bb)).b$/x ? "yes":"no"; # -> no (corre +ct)

The first case incorrectly matches. However, introducing a dummy eval (?{}) in the second case produces the correct result...

The 'use re 'Debug' => "EXECUTE";' shows the execution differences (both versions compile to the same code — except for the eval, obviously):

Guessing start of match in sv for REx "^(?(?!a) (?=bb)).b$" against "x +b" Guessed: match at offset 0 Matching REx "^(?(?!a) (?=bb)).b$" against "xb" 0 <> <xb> | 1:BOL(2) 0 <> <xb> | 2:LOGICAL[1](3) 0 <> <xb> | 3:UNLESSM[0](9) 0 <> <xb> | 5: EXACT <a>(7) failed... 0 <> <xb> | 9:IFTHEN(20) 0 <> <xb> | 11:IFMATCH[0](20) 0 <> <xb> | 13: EXACT <bb>(15) failed... 0 <> <xb> | 20:REG_ANY(21) <-- incorrectly cont +inues here 1 <x> <b> | 21:EXACT <b>(23) 2 <xb> <> | 23:EOL(24) 2 <xb> <> | 24:END(0) Match successful! yes Guessing start of match in sv for REx "^(?(?!a) (?{}) (?=bb)).b$" agai +nst "xb" Guessed: match at offset 0 Matching REx "^(?(?!a) (?{}) (?=bb)).b$" against "xb" 0 <> <xb> | 1:BOL(2) 0 <> <xb> | 2:LOGICAL[1](3) 0 <> <xb> | 3:UNLESSM[0](9) 0 <> <xb> | 5: EXACT <a>(7) failed... 0 <> <xb> | 9:IFTHEN(22) 0 <> <xb> | 11:EVAL(13) 0 <> <xb> | 13:IFMATCH[0](22) 0 <> <xb> | 15: EXACT <bb>(17) failed... failed... Match failed no

In reply to Re^4: Oddity with Conditional Regex (bug!) by almut
in thread Oddity with Conditional Regex by Rabscuttle

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.