我想从字符串中匹配可能的名称。名称应为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)
它适用于前三行,但不适用于最后一行。
森林海
Qyouu
相关分类