Is

/ ( (?<=prefix) (infix) (?=suffix) ) (??{ print $^N }) /gx
really the same as
/ prefix (infix) suffix (??{ print $^N }) /gx
as far as $^N = 'infix' is concerned? Actually I can't seem to find any net differences in the above. I came to this presumption after having used the former for awhile and tested it with a fairly simple RE (such as the above), but wanted to confirm this is universally true for literal strings and ask if it might break otherwise.

Similarly, if they are equivalent, why doesn't

/ ( (?<=some(optional)?prefix) (infix) (?=suffix) ) (??{ print $^N }) /gx
optimize away to
/ some(optional)?prefix (infix) suffix (??{ print $^N }) /gx
instead of resulting in the Variable length lookbehind not implemented in regex error?

Lastly, (this might be redundant given answers to the above, but) when is usage of ?<= and ?= appropriate? The only possibility I can think of is something involving nested (), but I can only think of contrived examples at the moment. I seem to recall needing them in the past, but I can't seem to recall the implementation...


In reply to 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.