Splitting a person's name into forename and surname

前端 未结 16 2007
北海茫月
北海茫月 2020-12-05 10:46

ok so basically I am asking the question of their name I want this to be one input rather than Forename and Surname.

Now is there any way of splitting this name? and

16条回答
  •  悲哀的现实
    2020-12-05 11:06

    Since there are so many different variation's of how people write their names, but here's how a basic way to get the first/lastname via regex.

    import re
    p = re.compile(r'^(\s+)?(Mr(\.)?|Mrs(\.)?)?(?P.+)(\s+)(?P.+)$', re.IGNORECASE)
    m = p.match('Mr. Dingo Bat')
    if(m != None):
      first_name = m.group('FIRST_NAME')
      last_name = m.group('LAST_NAME')
    

提交回复
热议问题