擅长:python、mysql、java
<p>使用<code>re.search</code></p>
<pre><code>>>> import re
>>> s = 'Part 1. Part 2. Part 3 then more text'
>>> re.search(r'Part 1\.(.*?)Part 3', s).group(1)
' Part 2. '
>>> re.search(r'Part 1(.*?)Part 3', s).group(1)
'. Part 2. '
</code></pre>
<p>或者使用<code>re.findall</code>,如果有多个发生。</p>