Because this is Perl, There Is More Than One Way To Do It. The re module is in core, and will produce a trace of both the compilation and execution of a regular expression. In this case:

$  perl -Mre=debug -e '"okoK" =~ /(o|k)(k|i)(O|K)(K)/'
Compiling REx "(o|k)(k|i)(O|K)(K)"
Final program:
   1: OPEN1 (3)
   3:   TRIE-EXACTko (9)
        <o> 
        <k> 
   9: CLOSE1 (11)
  11: OPEN2 (13)
  13:   TRIE-EXACTik (19)
        <k> 
        <i> 
  19: CLOSE2 (21)
  21: OPEN3 (23)
  23:   TRIE-EXACTKO (29)
        <O> 
        <K> 
  29: CLOSE3 (31)
  31: OPEN4 (33)
  33:   EXACT <K> (35)
  35: CLOSE4 (37)
  37: END (0)
anchored "K" at 3..3 (checking anchored) stclass AHOCORASICK-EXACTko minlen 4 
Matching REx "(o|k)(k|i)(O|K)(K)" against "okoK"
Intuit: trying to determine minimum start position...
  doing 'check' fbm scan, 3..4 gave 3
  Found anchored substr "K" at offset 3 (rx_origin now 0)...
  (multiline anchor test skipped)
Intuit: Successfully guessed: match at offset 0
   0 <> <okoK>               |   0| 1:OPEN1(3)
   0 <> <okoK>               |   0| 3:TRIE-EXACTko(9)
   0 <> <okoK>               |   0| TRIE: State:    1 Accepted: N TRIE: Charid:  1 CP:  6f After State:    2
   1 <o> <koK>               |   0| TRIE: State:    2 Accepted: Y TRIE: Charid:  0 CP:   0 After State:    0
                             |   0| TRIE: got 1 possible matches
                             |   0| TRIE matched word #1, continuing
                             |   0| TRIE: only one match left, short-circuiting: #1 <o>
   1 <o> <koK>               |   0| 9:CLOSE1(11)
   1 <o> <koK>               |   0| 11:OPEN2(13)
   1 <o> <koK>               |   0| 13:TRIE-EXACTik(19)
   1 <o> <koK>               |   0| TRIE: State:    1 Accepted: N TRIE: Charid:  1 CP:  6b After State:    2
   2 <ok> <oK>               |   0| TRIE: State:    2 Accepted: Y TRIE: Charid:  0 CP:   0 After State:    0
                             |   0| TRIE: got 1 possible matches
                             |   0| TRIE matched word #1, continuing
                             |   0| TRIE: only one match left, short-circuiting: #1 <k>
   2 <ok> <oK>               |   0| 19:CLOSE2(21)
   2 <ok> <oK>               |   0| 21:OPEN3(23)
   2 <ok> <oK>               |   0| 23:TRIE-EXACTKO(29)
                             |   0| TRIE: failed to match trie start class...
Match failed
Freeing REx: "(o|k)(k|i)(O|K)(K)"

If you are using Windows, you will need to use " where my example has ', and vice versa.


In reply to Re: Tell or determine whichever Perl regex group fails by Anonymous Monk
in thread Tell or determine whichever Perl regex group fails by Anonymous Monk

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.