私はすべての英語の名前を検索するために以下のようなPythonコードを持っています:
a = "Bonds met Susann ("Sun") Margreth Branco, the mother of his first two children, in {{city-state|Montreal|Quebec}} in August 1987. They eloped in {{city-state|Las Vegas|Nevada}} Barry Bonds"
re.findall("(?:[A-Z][a-z'.]+\s*){1,4}",a)
私はそれを返したい:
['Bonds', 'Susann ("Sun") Margreth Branco', 'Montreal', 'Quebec', 'August', 'They', 'Las Vegas','Nevada','Barry Bonds']
私のコードは私が望むものを得ることができません、私の目標を達成するために正規表現を変更する方法は?
また、別の正規表現を使用したことを付け加えたいと思い(?:(([A-Z][a-z'.]+)|(\(".*"\)))\s*){1,4}
ます。regexpal.comでテストすると、そのテストWebサイトで必要なものが見つかりますが、Pythonでは、必要なものが返されませんがSusan
、と、("Sun") Margreth
およびBranco
、3つが別々に返されますがSusan ("Sun") Margreth Branco
、結果には必要です。