Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

The  use re 'debug'; statement/pragma (see re) is useful to gain insight into what the Perl regex compiler thinks you wrote.

The debug output is just a teensy bit opaque, but some insight can be had just by noting that in both cases below, the  'a' literal substring part of the regex is denoted as
     6:   EXACT <a> (8)
whereas in the case that doesn't work, what you think is a counted quantifier is denoted
    14:   EXACT <{0, 5}> (17)
(i.e., the regex compiler thinks it's a  '{0, 5}' literal substring), versus
    13:   CURLY {0,5} (16)
    15:     REG_ANY (0)
in the case of the correctly written counted quantifier (the one that works as expected).

>perl -wMstrict -le "use re 'debug'; ;; my $rx = qr/(?<WORD>\b\w*a\b)(?<EXTRA>.{0, 5})/; " Compiling REx "(?<WORD>\b\w*a\b)(?<EXTRA>.{0, 5})" Final program: 1: OPEN1 'WORD' (3) 3: BOUND (4) 4: STAR (6) 5: ALNUM (0) 6: EXACT <a> (8) 8: BOUND (9) 9: CLOSE1 'WORD' (11) 11: OPEN2 'EXTRA' (13) 13: REG_ANY (14) 14: EXACT <{0, 5}> (17) 17: CLOSE2 'EXTRA' (19) 19: END (0) floating "{0, 5}" at 2..2147483647 (checking floating) stclass BOUND m +inlen 8 Freeing REx: "(?<WORD>\b\w*a\b)(?<EXTRA>.{0, 5})" >perl -wMstrict -le "use re 'debug'; ;; my $rx = qr/(?<WORD>\b\w*a\b)(?<EXTRA>.{0,5})/; " Compiling REx "(?<WORD>\b\w*a\b)(?<EXTRA>.{0,5})" Final program: 1: OPEN1 'WORD' (3) 3: BOUND (4) 4: STAR (6) 5: ALNUM (0) 6: EXACT <a> (8) 8: BOUND (9) 9: CLOSE1 'WORD' (11) 11: OPEN2 'EXTRA' (13) 13: CURLY {0,5} (16) 15: REG_ANY (0) 16: CLOSE2 'EXTRA' (18) 18: END (0) floating "a" at 0..2147483647 (checking floating) stclass BOUND minlen + 1 Freeing REx: "(?<WORD>\b\w*a\b)(?<EXTRA>.{0,5})"

The YAPE::Regex::Explain module can also offer helpful insight, but unfortunately it doesn't support regex constructs much beyond Perl version 5.6 and that's just what you're using!


In reply to Re^3: Why this Regex code is not working?? by AnomalousMonk
in thread Why this Regex code is not working?? by Rohit Jain

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2014-12-26 23:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (176 votes), past polls