我试图通过假设它们在表单上来捕捉名字Firstname Lastlame。这适用于下面的代码,但我希望能够捕获国际名称,如Pär Åberg. 我找到了一些解决方案,但不幸的是,它们似乎不适用于 Python 风格的正则表达式。有没有人对此有所了解?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
text = """
This is a text containing names of people in the text such as
Hillary Clinton or Barack Obama. My problem is with names that uses stuff
outside A-Z like Swedish names such as Pär Åberg."""
for name in re.findall("(([A-Z])[\w-]*(\s+[A-Z][\w-]*)+)", text):
firstname = name[0].split()[0]
print firstname
Run Code Online (Sandbox Code Playgroud)