擅长:python、mysql、java
<p>您当前的regex使用<code>[\s,\S]+</code>,这是贪婪的,匹配所有字符,直到行尾。在</p>
<p>您可以将其设为非贪心的,并对最后一个断言以下内容的匹配使用一个正的lookahead <code>(?=string|$)</code>,该匹配要么是{<cd3>},要么是行尾{<cd4>}。在</p>
<p><a href="https://regex101.com/r/2Qnhsw/1" rel="nofollow noreferrer">^{<cd5>}</a></p>
<pre><code>import re
s = 'string1:1234string2string3:a1b2c3string1:2345string3:b5c6d7'
print(re.findall('string1:(\d+).*?string3:(.*?)(?=string|$)',s))
</code></pre>
<p><a href="http://rextester.com/PNOOI52036" rel="nofollow noreferrer">Demo</a></p>