Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't found any nice debugging utility for PCRE regexps. The more I could find was how to dump the bytecode:</p> <pre><code>$ pcretest -b PCRE version 7.6 2008-01-28 re&gt; /^((.)(?1)\2|.?)$/x ------------------------------------------------------------------ 0 39 Bra 3 ^ 4 26 CBra 1 9 6 CBra 2 14 Any 15 6 Ket 18 6 Once 21 4 Recurse 24 6 Ket 27 \2 30 5 Alt 33 Any? 35 31 Ket 38 $ 39 39 Ket 42 End ------------------------------------------------------------------ </code></pre> <p>Perl has better debugging tools than PCRE, try <code>echo 123454321 | perl -Mre=debug -ne '/^((.)(?1)\2|.?)$/x'</code>. This gives not only some bytecode that is similar to PCRE's one, but it also shows each step, and the consumed and remaining parts of the input at each step:</p> <pre><code>Compiling REx "^((.)(?1)\2|.?)$" Final program: 1: BOL (2) 2: OPEN1 (4) 4: BRANCH (15) 5: OPEN2 (7) 7: REG_ANY (8) 8: CLOSE2 (10) 10: GOSUB1[-8] (13) 13: REF2 (19) 15: BRANCH (FAIL) 16: CURLY {0,1} (19) 18: REG_ANY (0) 19: CLOSE1 (21) 21: EOL (22) 22: END (0) floating ""$ at 0..2147483647 (checking floating) anchored(BOL) minlen 0 Guessing start of match in sv for REx "^((.)(?1)\2|.?)$" against "12321" Found floating substr ""$ at offset 5... Guessed: match at offset 0 Matching REx "^((.)(?1)\2|.?)$" against "12321" 0 &lt;&gt; &lt;12321&gt; | 1:BOL(2) 0 &lt;&gt; &lt;12321&gt; | 2:OPEN1(4) 0 &lt;&gt; &lt;12321&gt; | 4:BRANCH(15) 0 &lt;&gt; &lt;12321&gt; | 5: OPEN2(7) 0 &lt;&gt; &lt;12321&gt; | 7: REG_ANY(8) 1 &lt;1&gt; &lt;2321&gt; | 8: CLOSE2(10) 1 &lt;1&gt; &lt;2321&gt; | 10: GOSUB1[-8](13) 1 &lt;1&gt; &lt;2321&gt; | 2: OPEN1(4) 1 &lt;1&gt; &lt;2321&gt; | 4: BRANCH(15) 1 &lt;1&gt; &lt;2321&gt; | 5: OPEN2(7) 1 &lt;1&gt; &lt;2321&gt; | 7: REG_ANY(8) 2 &lt;12&gt; &lt;321&gt; | 8: CLOSE2(10) 2 &lt;12&gt; &lt;321&gt; | 10: GOSUB1[-8](13) 2 &lt;12&gt; &lt;321&gt; | 2: OPEN1(4) 2 &lt;12&gt; &lt;321&gt; | 4: BRANCH(15) 2 &lt;12&gt; &lt;321&gt; | 5: OPEN2(7) 2 &lt;12&gt; &lt;321&gt; | 7: REG_ANY(8) 3 &lt;123&gt; &lt;21&gt; | 8: CLOSE2(10) 3 &lt;123&gt; &lt;21&gt; | 10: GOSUB1[-8](13) 3 &lt;123&gt; &lt;21&gt; | 2: OPEN1(4) 3 &lt;123&gt; &lt;21&gt; | 4: BRANCH(15) 3 &lt;123&gt; &lt;21&gt; | 5: OPEN2(7) 3 &lt;123&gt; &lt;21&gt; | 7: REG_ANY(8) 4 &lt;1232&gt; &lt;1&gt; | 8: CLOSE2(10) 4 &lt;1232&gt; &lt;1&gt; | 10: GOSUB1[-8](13) 4 &lt;1232&gt; &lt;1&gt; | 2: OPEN1(4) 4 &lt;1232&gt; &lt;1&gt; | 4: BRANCH(15) 4 &lt;1232&gt; &lt;1&gt; | 5: OPEN2(7) 4 &lt;1232&gt; &lt;1&gt; | 7: REG_ANY(8) 5 &lt;12321&gt; &lt;&gt; | 8: CLOSE2(10) 5 &lt;12321&gt; &lt;&gt; | 10: GOSUB1[-8](13) 5 &lt;12321&gt; &lt;&gt; | 2: OPEN1(4) 5 &lt;12321&gt; &lt;&gt; | 4: BRANCH(15) 5 &lt;12321&gt; &lt;&gt; | 5: OPEN2(7) 5 &lt;12321&gt; &lt;&gt; | 7: REG_ANY(8) failed... 5 &lt;12321&gt; &lt;&gt; | 15: BRANCH(19) 5 &lt;12321&gt; &lt;&gt; | 16: CURLY {0,1}(19) REG_ANY can match 0 times out of 1... 5 &lt;12321&gt; &lt;&gt; | 19: CLOSE1(21) EVAL trying tail ... 9d86dd8 5 &lt;12321&gt; &lt;&gt; | 13: REF2(19) failed... failed... BRANCH failed... 4 &lt;1232&gt; &lt;1&gt; | 15: BRANCH(19) 4 &lt;1232&gt; &lt;1&gt; | 16: CURLY {0,1}(19) REG_ANY can match 1 times out of 1... 5 &lt;12321&gt; &lt;&gt; | 19: CLOSE1(21) EVAL trying tail ... 9d86d70 5 &lt;12321&gt; &lt;&gt; | 13: REF2(19) failed... 4 &lt;1232&gt; &lt;1&gt; | 19: CLOSE1(21) EVAL trying tail ... 9d86d70 4 &lt;1232&gt; &lt;1&gt; | 13: REF2(19) failed... failed... BRANCH failed... 3 &lt;123&gt; &lt;21&gt; | 15: BRANCH(19) 3 &lt;123&gt; &lt;21&gt; | 16: CURLY {0,1}(19) REG_ANY can match 1 times out of 1... 4 &lt;1232&gt; &lt;1&gt; | 19: CLOSE1(21) EVAL trying tail ... 9d86d08 4 &lt;1232&gt; &lt;1&gt; | 13: REF2(19) failed... 3 &lt;123&gt; &lt;21&gt; | 19: CLOSE1(21) EVAL trying tail ... 9d86d08 3 &lt;123&gt; &lt;21&gt; | 13: REF2(19) failed... failed... BRANCH failed... 2 &lt;12&gt; &lt;321&gt; | 15: BRANCH(19) 2 &lt;12&gt; &lt;321&gt; | 16: CURLY {0,1}(19) REG_ANY can match 1 times out of 1... 3 &lt;123&gt; &lt;21&gt; | 19: CLOSE1(21) EVAL trying tail ... 9d86ca0 3 &lt;123&gt; &lt;21&gt; | 13: REF2(19) 4 &lt;1232&gt; &lt;1&gt; | 19: CLOSE1(21) EVAL trying tail ... 0 4 &lt;1232&gt; &lt;1&gt; | 13: REF2(19) 5 &lt;12321&gt; &lt;&gt; | 19: CLOSE1(21) 5 &lt;12321&gt; &lt;&gt; | 21: EOL(22) 5 &lt;12321&gt; &lt;&gt; | 22: END(0) Match successful! Freeing REx: "^((.)(?1)\2|.?)$" </code></pre> <p>As you can see, Perl first consumes all input recursing until <code>(.)</code> fails, then starts backtracking and trying the second branch from the alternation <code>.?</code> and the remainder of the first part <code>\2</code>, when that fails it backtracks, until it finally succeeds.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload