Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your first expression the lookahead assertion is matching your input as (<code>greedy</code>). </p> <p>Running a debug test on your regular expression displays the following.</p> <pre><code>Matching REx "(?=.*\d)\w{4,}" against "!abcae20" 0 &lt;&gt; &lt;!abcae20&gt; | 1: IFMATCH[0](8) 0 &lt;&gt; &lt;!abcae20&gt; | 3: STAR(5) REG_ANY can match 8 times out of 2147483647... 8 &lt;!abcae20&gt; &lt;&gt; | 5: DIGIT(6) failed... 7 &lt;!abcae2&gt; &lt;0&gt; | 5: DIGIT(6) 8 &lt;!abcae20&gt; &lt;&gt; | 6: SUCCEED(0) subpattern success... 0 &lt;&gt; &lt;!abcae20&gt; | 8: CURLY {4,32767}(11) ALNUMU can match 0 times out of 2147483647... failed... Match failed </code></pre> <ul> <li><p>Explanation on what caused the match to fail..</p> <ol> <li><p>&lt;<strong>!abcae20</strong>></p> <pre><code>The greedy quantifier first matches as much as possible. So the .* here is matching the entire string. </code></pre></li> <li><p>&lt;<code>!abcae20</code>></p> <pre><code>Then tries to match any numeric character following, but there are no characters left to match. </code></pre></li> <li><p>&lt;<code>!abcae2</code><strong>0</strong>></p> <pre><code>So it backtracks making the greedy match, match one less character leaving the --&gt; 0 &lt;-- at the end unmatched. </code></pre></li> <li><p>&lt;<code>!abcae20</code>></p> <pre><code>So it backtracks again matching one less leaving it unmatched. </code></pre></li> <li><p>&lt;<strong>!abcae20</strong>></p> <pre><code>So it backtracks one more step matching one less again and failing your match. </code></pre></li> </ol></li> <li><p>Regular expression explained:</p> <pre><code>(?= look ahead to see if there is: .* any character except \n (0 or more times) \d digits (0-9) ) end of look-ahead \w{4,} word characters (a-z, A-Z, 0-9, _) (at least 4 times) </code></pre></li> </ul> <p>Your second expression does match <code>!</code> with the preceding non-greedy <code>.*?</code> followed by your lookahead assertion which matches <code>!abcae2</code>, then backtracks to match your word characters and complete string.</p> <ul> <li><p>Regular expression explained:</p> <pre><code>.*? any character except \n (0 or more times) (?= look ahead to see if there is: .* any character except \n (0 or more times) \d digits (0-9) ) end of look-ahead \w{4,} word characters (a-z, A-Z, 0-9, _) (at least 4 times) </code></pre></li> </ul>
 

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