擅长:python、mysql、java
<p>因为你所拥有的是贪婪的</p>
<p>尝试懒惰:</p>
<pre><code>re.findall(r'ad</div>.*?<div>(.*?)</div>',x,re.S)
</code></pre>
<p>在您的示例中,<code>.*</code>实际上是在最后匹配所有内容,然后它看到<code><div></code>,然后您的regex会重新跟踪并重新开始匹配,类似的是第二个场景</p>
<p>此处演示:</p>
<p><a href="http://regex101.com/r/zY9xA3/1" rel="nofollow">http://regex101.com/r/zY9xA3/1</a></p>