擅长:python、mysql、java
<p>最简单的解决方案是让它变懒:</p>
<pre><code>RX\[\d+\].*?packets\s+:\s+(\d+)
</code></pre>
<p>请看<a href="https://regex101.com/r/cUQHmB/1" rel="nofollow noreferrer"><strong>working on regex101.com</strong></a>。<br/>
否则,您的<code>.*</code>构造会占用<strong><em>整个字符串</em></strong>并在之后回溯(即找到最后一个<code>packets</code>时成功)。<br/>
</p><hr/>
会是另一个:
^{pr2}$
<p>请参见<a href="https://regex101.com/r/cUQHmB/3" rel="nofollow noreferrer"><strong>this one working here</strong></a>(注意不同的修改器!)。在</p>