Skip to content

Instantly share code, notes, and snippets.

@llimllib

llimllib/gist:255011

Created Dec 12, 2009
Embed
What would you like to do?
def parse_name(name):
#delete (nicknames)
name = re.sub("\(.*?\)", "", name)
names = name.split(" ")
first_name = names[0]
if len(names) > 2:
middle_names = [names[1]]
for i, n in enumerate(names[2:]):
if re.search("\w\.$", n.strip()):
middle_names.append(n)
else: break
middle_name = " ".join(middle_names)
last_name = " ".join(names[i+2:])
else:
middle_name = ""
last_name = names[1]
#steal jr.s or sr.s
suffix = re.findall(", (\w*?)\.", last_name) or ""
if suffix:
suffix = suffix[0]
last_name = re.sub(", \w*?\.", "", last_name)
return (first_name, middle_name, last_name, suffix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.