What is the difference between them? The difference is code snippet 2 is using one more named capture <P_NEW_MON_CODE>. What output are they supposed to give? Code snippet 1 is gving output as (value 'RS S') Value of p_rootcode in Pattern 1 is : RS R Code snippet 2 is gving output as below (no value printed) Value of p_rootcode in Pattern 2 is : Why oneliner regex, why not you use /x? How can I hope to use regular expressions without creating illegible and unmaintainable code? Sorry about that. Why did you use named patterns with $^MATCH? And with code callbacks? Named patterns used for saving the sub matches so that it can be used in later part of the code. Why did you use \K twice? Please ignore this as even if \K is not used still both code snippets are behaving same. Have you heard of rxrx? In this example it doesnt help why the output values are different.


In reply to Re^2: Question on Regular Expression by sjain
in thread Question on Regular Expression by sjain

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.