Note that there are some explanatory texts on larger screens.

plurals
  1. PO100% CPU usage with a regexp depending on input length
    primarykey
    data
    text
    <p>I'm trying to come up with a regexp in Python that has to match any character but avoiding three or more consecutive commas or semicolons. In other words, only up to two consecutive commas or semicolons are allowed.</p> <p>So this is what I currently have:</p> <pre><code>^(,|;){,2}([^,;]+(,|;){,2})*$ </code></pre> <p>And it seems to work as expected:</p> <pre><code>&gt;&gt;&gt; r.match('') &lt;_sre.SRE_Match object at 0x7f23af8407e8&gt; &gt;&gt;&gt; r.match('foo,') &lt;_sre.SRE_Match object at 0x7f23af840750&gt; &gt;&gt;&gt; r.match('foo, a') &lt;_sre.SRE_Match object at 0x7f23af8407e8&gt; &gt;&gt;&gt; r.match('foo, ,') &lt;_sre.SRE_Match object at 0x7f23af840750&gt; &gt;&gt;&gt; r.match('foo, ,,a') &lt;_sre.SRE_Match object at 0x7f23af8407e8&gt; &gt;&gt;&gt; r.match('foo, ,,,') &gt;&gt;&gt; r.match('foo, ,,,;') &gt;&gt;&gt; r.match('foo, ,, ;;') &lt;_sre.SRE_Match object at 0x7f23af840750&gt; </code></pre> <p>But as I start to increase the length of the input text, the regexp seems to need way more time to give a response.</p> <pre><code>&gt;&gt;&gt; r.match('foo, bar, baz,, foo') &lt;_sre.SRE_Match object at 0x7f23af8407e8&gt; &gt;&gt;&gt; r.match('foo, bar, baz,, fooooo, baaaaar') &lt;_sre.SRE_Match object at 0x7f23af840750&gt; &gt;&gt;&gt; r.match('foo, bar, baz,, fooooo, baaaaar,') &lt;_sre.SRE_Match object at 0x7f23af8407e8&gt; &gt;&gt;&gt; r.match('foo, bar, baz,, fooooo, baaaaar,,') &lt;_sre.SRE_Match object at 0x7f23af840750&gt; &gt;&gt;&gt; r.match('foo, bar, baz,, fooooo, baaaaar,,,') &gt;&gt;&gt; r.match('foo, bar, baz,, fooooo, baaaaar,,,,') &gt;&gt;&gt; r.match('foo, bar, baz,, fooooo, baaaaar, baaaaaaz,,,,') </code></pre> <p>And finally it gets completely stuck at this stage and the CPU usage goes up to 100%.</p> <p>I'm not sure if the regexp could be optimized or there's something else involved, any help appreciated.</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.
 

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