Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're running into <a href="http://www.regular-expressions.info/catastrophic.html" rel="noreferrer">catastrophic backtracking</a>.</p> <p>The reason for this is that you have made the separators optional, and therefore the <code>[^,;]+</code> part (which is itself in a repeating group) of your regex will try loads of permutations (of <code>baaaaaaaz</code>) before finally having to admit failure when confronted with more than two commas.</p> <p><a href="http://www.regexbuddy.com" rel="noreferrer">RegexBuddy</a> aborts the match attempt after 1.000.000 steps of the regex engine with your last test string. Python will keep trying.</p> <p>Imagine the string <code>baaz,,,</code>:</p> <p>Trying your regex, the regex engine has to check all these:</p> <ol> <li><code>baaz,,&lt;failure&gt;</code></li> <li><code>baa</code> + <code>z,,&lt;failure&gt;</code></li> <li><code>ba</code> + <code>az,,&lt;failure&gt;</code></li> <li><code>ba</code> + <code>a</code> + <code>z,,&lt;failure&gt;</code></li> <li><code>b</code> + <code>aaz,,&lt;failure&gt;</code></li> <li><code>b</code> + <code>aa</code> + <code>z,,&lt;failure&gt;</code></li> <li><code>b</code> + <code>a</code> + <code>az,,&lt;failure&gt;</code></li> <li><code>b</code> + <code>a</code> + <code>a</code> +<code>z,,&lt;failure&gt;</code></li> </ol> <p>before declaring overall failure. See how this grows exponentially with each additional character?</p> <p>Behavior like this can be avoided with possessive quantifiers or atomic groups, both of which are sadly not supported by Python's current regex engine. But you can do an inverse check easily:</p> <pre><code>if ",,," in mystring or ";;;" in mystring: fail() </code></pre> <p>without needing a regex at all. If <code>,;,</code> and the likes could also occur and should be excluded, then use Andrew's solution.</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