First, do you realize
(??{ print $^N })
is causing the regexp to try to match "1", the return value of print? You should probably use something that's guaranteed not to match like
(??{ print("$^N\n"); '(?!)' })
or something that's guaranteed to match like
(??{ print("$^N\n"); '(?=)' })
(depending on your intention) instead of relying on the return value of print and the presence/absence of the return value of print in the string to match.

You use /g, so I assume you'll call the regexp more than once in a scalar context, or in a list context.

So compare

local $_ = 'aaaaabaaaaab'; 1 while / ( (?<=a) (a) (?=[ab]) ) (??{ print $^N; '(?=)' }) /gx; print("\n");

with

local $_ = 'aaaaabaaaaab'; 1 while / a (a) [ab] (??{ print $^N; '(?=)' }) /gx; print("\n");

The first outputs "aaaaaaaa", which the second outputs "aaaa".

(?=...) is useful when followed by something which isn't zero-width, when /g is used and when used in substititutions.

(?<=...) is useful when /g is used and when used in substititutions.


In reply to Re: Regular Expression Constructs ?<= and ?= by ikegami
in thread Regular Expression Constructs ?<= and ?= by eibwen

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.