Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Besides what Hans Kesting already said, a lazy multiplier will do the exact oposite of the normal greedy multipliers: The possible match is kept as small as possible and the rest of the regular expression is tested.</p> <p>So if you’re having the string <code>aaba</code> and test the regular expression <code>a.*b</code> on it, the internal processing steps would be as follows:</p> <ol> <li><strong><code>a</code></strong> in <strong><code>a</code></strong><code>.*b</code> matches <strong><code>a</code></strong><code>aba</code></li> <li><strong><code>.*</code></strong> in <code>a</code><strong><code>.*</code></strong><code>b</code> matches <code>a</code><strong><code>a</code></strong><code>ba</code>, and since <code>.*</code> is greedy <ol start="3"> <li><strong><code>.*</code></strong> then matches <code>a</code><strong><code>ab</code></strong><code>a</code></li> <li><strong><code>.*</code></strong> then matches <code>a</code><strong><code>aba</code></strong></li> </ol></li> <li><strong><code>b</code></strong> in <code>a.*</code><strong><code>b</code></strong> fails as there is no letter left <ul> <li>backtracking goes one step back and <code>.*</code> will now only match <code>bb</code> in <code>a</code><strong><code>ab</code></strong><code>a</code></li> </ul></li> <li><strong><code>b</code></strong> in <code>a.*</code><strong><code>b</code></strong> still fails on <code>aab</code><strong><code>a</code></strong> <ul> <li>backtracking goes one step back and <code>.*</code> now matches only <code>b</code> in <code>a</code><strong><code>a</code></strong><code>ba</code></li> </ul></li> <li><strong><code>b</code></strong> in <code>a.*</code><strong><code>b</code></strong> now matches <code>b</code> in <code>aa</code><strong><code>b</code></strong><code>a</code> and we’re done.</li> </ol> <p>So the full match is <strong><code>aab</code></strong><code>a</code>.</p> <p>If we do the same with a lazy multiplier (<code>a.*?b</code>), the processing will do the oposite, try to match the least possible characters as possible:</p> <ol> <li><strong><code>a</code></strong> in <strong><code>a</code></strong><code>.*?b</code> matches <strong><code>a</code></strong><code>aba</code></li> <li><strong><code>.*</code></strong> in <code>a</code><strong><code>.*</code></strong><code>?b</code> matches nothing (<code>*</code> = zero or more repetitions), and since <code>.*</code> is declared as lazy (<code>.*?</code>), the rest of the regular expression is tested</li> <li><strong><code>b</code></strong> in <code>a.*?</code><strong><code>b</code></strong> fails on <code>a</code><strong><code>a</code></strong><code>ba</code> <ul> <li>backtracking will try to increase the match of <code>.*</code></li> </ul></li> <li><strong><code>.*</code></strong> matches now <code>a</code><strong><code>a</code></strong><code>ba</code></li> <li><strong><code>b</code></strong> in <code>a.*?</code><strong><code>b</code></strong> matches <code>aa</code><strong><code>b</code></strong><code>a</code> and we’re done.</li> </ol> <p>So the full match if <strong><code>aab</code></strong><code>a</code>.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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