擅长:python、mysql、java
<p>使用正则表达式:</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. '
</code></pre>
<p>如果不使用正则表达式,此表达式适用于您的示例:</p>
<pre><code>>>> s = 'Part 1. Part 2. Part 3 then more text'
>>> a, b = s.find('Part 1'), s.find('Part 3')
>>> s[a+6:b]
'. Part 2. '
</code></pre>