擅长:python、mysql、java
<pre><code>I believe the regex
<bla><blabla>87765.*?</blabla><bla>
can produce catastrophic backtracking.
Instead, use:
<bla><blabla>87765[^<]*</blabla><bla>
Using atomic grouping (I'm not sure Python supports this),
the above regex becomes
<bla><blabla>(?>(.*?<))/blabla><bla>
</code></pre>
<p>之间的一切?>;…)一旦regex引擎离开组,regex引擎就将其视为一个令牌。因为整个组是一个令牌,所以一旦regex引擎找到组的匹配项,就不能进行回溯。如果需要回溯,引擎必须在组之前回溯到regex标记(在我们的示例中是插入符号)。如果组之前没有标记,则正则表达式必须在字符串的下一个位置重试整个正则表达式。请注意,我需要在组中包含“<;”,以确保原子性。够近了。</p>