擅长:python、mysql、java
<p>您可以使用<em>正向先行断言</em><code>(?=...)</code>来检查单词以单个大写字符结尾,然后使用单词boudaries<code>\b...\b</code>来确保它与不是整个单词的模式不匹配:</p>
<pre><code>>>> text = "This re will match MonsterA and HeroB but not heroC or MonsterCC"
>>> re.findall(r"\b[A-Z][a-z]+(?=[A-Z]\b)", text)
['Monster', 'Hero']
</code></pre>
<p><code>re.findall</code>返回列表中的所有匹配项</p>