It matches becuase the \d{1,3} can match a single digit, then the second digit satisfies the lookahead.

If you run the code with  -Mre=debug you can see it first matching two digits, then matching the lookahead string (thus failing), backtracking, trying to match a single digit, then succeeding:

Setting an EVAL scope, savestack=5 0 <> <2005-12-> | 1: CURLY {4,4} DIGIT can match 4 times out of 4... Setting an EVAL scope, savestack=5 4 <2005> <-12-> | 4: EXACT <-> 5 <2005-> <12-> | 6: CURLY {1,3} DIGIT can match 2 times out of 3... Setting an EVAL scope, savestack=5 7 <2005-12> <-> | 9: UNLESSM[-0] 7 <2005-12> <-> | 11: EXACT <-> 8 <2005-12-> <> | 13: SUCCEED could match... failed... 6 <2005-1> <2-> | 9: UNLESSM[-0] 6 <2005-1> <2-> | 11: EXACT <-> failed... 6 <2005-1> <2-> | 15: END Match successful!

Dave.


In reply to Re: negative look-ahead is ignored by dave_the_m
in thread negative look-ahead is ignored by jeanluca

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.