我想从字符串中匹配可能的名称。名称应为 2-4 个单词,每个单词包含 3 个或更多字母,所有单词大写。例如,给定以下字符串列表:
Her name is Emily.
I work for Surya Soft.
I sent an email for Ery Wulandari.
Welcome to the Link Building Partner program!
我想要一个返回的正则表达式:
None
Surya Soft
Ery Wulandari
Link Building Partner
目前这是我的代码:
data = [
'Her name is Emily.',
'I work for Surya Soft.',
'I sent an email for Ery Wulandari.',
'Welcome to the Link Building Partner program!'
]
for line in data:
print re.findall('(?:[A-Z][a-z0-9]{2,}\s+[A-Z][a-z0-9]{2,})', line)
它适用于前三行,但在最后一行失败。