<p>在regexr.com我开发了一个正则表达式来匹配特定类型的专有名称。以下是表达式:</p>
<pre><code>\b([a-z]?[A-Z]+[\w]*[ ]*)+\b
</code></pre>
<p>您可以看到它与许多实例在现场进行匹配
<a href="http://regexr.com/3bifh" rel="nofollow">http://regexr.com/3bifh</a></p>
<p>例如,赫尔曼·梅尔维尔(Herman Melville)的《白鲸》(the White Whale)或《白鲸》(the Moby Dick)中的一根弦与<code>Moby Dick</code>、<code>White Whale</code>和<code>Herman Melville</code>匹配</p>
<p>我正在尝试用Python复制这个,但没有那么成功。代码如下:</p>
<pre><code>import re
text = "Moby Dick or the White Whale by Herman Melville"
print(re.findall(r"\b([a-z]?[A-Z]+[\w]*[ ]*)+\b", text))
</code></pre>
<p>输出为:</p>
<pre><code>['Dick ', 'Whale ', 'Melville']
</code></pre>
<p>这只匹配上面每个结果的最后一部分。
为什么表达式在Python中不起作用?你知道吗</p>