Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you are proposing is difficult but <a href="https://stackoverflow.com/questions/2348694/how-do-you-debug-a-regex/2348711#2348711">doable</a>. </p> <p>If I can paraphrase what I understand, you are wanting to find out how far a failing match got into a match. In order to do this, you need to be able to parse a regex. </p> <p>The best regex parser is probably to use Perl itself with the <code>-re=debug</code> command line switch:</p> <pre><code>$ perl -Mre=debug -e'"abcdefghijklmnopqr"=~/gh[ijkl]{5}/' Compiling REx "gh[ijkl]{5}" Final program: 1: EXACT &lt;gh&gt; (3) 3: CURLY {5,5} (16) 5: ANYOF[i-l][] (0) 16: END (0) anchored "gh" at 0 (checking anchored) minlen 7 Guessing start of match in sv for REx "gh[ijkl]{5}" against "abcdefghijklmnopqr" Found anchored substr "gh" at offset 6... Starting position does not contradict /^/m... Guessed: match at offset 6 Matching REx "gh[ijkl]{5}" against "ghijklmnopqr" 6 &lt;bcdef&gt; &lt;ghijklmnop&gt; | 1:EXACT &lt;gh&gt;(3) 8 &lt;defgh&gt; &lt;ijklmnopqr&gt; | 3:CURLY {5,5}(16) ANYOF[i-l][] can match 4 times out of 5... failed... Match failed Freeing REx: "gh[ijkl]{5}" </code></pre> <p>You can shell out that Perl command line with your regex and parse the return of stdout. Look for the `</p> <p>Here is a matching regex:</p> <pre><code>$ perl -Mre=debug -e'"abcdefghijklmnopqr"=~/gh[ijkl]{3}/' Compiling REx "gh[ijkl]{3}" Final program: 1: EXACT &lt;gh&gt; (3) 3: CURLY {3,3} (16) 5: ANYOF[i-l][] (0) 16: END (0) anchored "gh" at 0 (checking anchored) minlen 5 Guessing start of match in sv for REx "gh[ijkl]{3}" against "abcdefghijklmnopqr" Found anchored substr "gh" at offset 6... Starting position does not contradict /^/m... Guessed: match at offset 6 Matching REx "gh[ijkl]{3}" against "ghijklmnopqr" 6 &lt;bcdef&gt; &lt;ghijklmnop&gt; | 1:EXACT &lt;gh&gt;(3) 8 &lt;defgh&gt; &lt;ijklmnopqr&gt; | 3:CURLY {3,3}(16) ANYOF[i-l][] can match 3 times out of 3... 11 &lt;ghijk&gt; &lt;lmnopqr&gt; | 16: END(0) Match successful! Freeing REx: "gh[ijkl]{3}" </code></pre> <p>You will need to build a parser that can handle <a href="http://perl.active-venture.com/pod/perldebguts-debugregexp.html" rel="nofollow noreferrer">the return</a> from the Perl re debugger. The left hand and right hand angle braces show the distance into the string as the regex engine is trying to match.</p> <p>This is not an easy project btw...</p>
 

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