擅长:python、mysql、java
<p>你就快到了。我刚刚修改了您的前瞻示例,添加了一个非贪婪的<code>.*</code>和一些细微的调整:</p>
<pre><code>(\d{4}\.\d{2,3}).*?(?=PLD GLTY)
</code></pre>
<p><strong>代码</strong>:</p>
<pre><code>import re
str = 'This is statute 2913.42 and defendant PLD GLTY, This is statute 2913.405 and defendant at pre-trial PLD GLTY, This is statute 2913.44 without any plea of guilt'
print(re.findall(r'(\d{4}\.\d{2,3}).*?(?=PLD GLTY)', str))
# ['2913.42', '2913.405']
</code></pre>
<p><code>d{2}\d?</code>最好写成<code>\d{2,3}</code>(数字总是出现2到3次)</p>
<p><a href="https://docs.python.org/3/library/functions.html#func-str" rel="nofollow noreferrer">^{<cd4>}</a>是Python中内置的,因此建议不要将其用作变量名、自定义函数名或其他任何名称,尽管我在这里使用它来匹配您的代码</p>