My current task is to create a (programming) algorithm which reverts a name's order. This since my country's formal name-listing order is different from international ones. The standard is often:

John Doe

However, the standard I must comply to has the following priority:

Doe, John

Our businesses often receives names in the international style, which needs to be converted to our national style.

However, I've yet to come up with a way to deal with double names and similar cases. As an example, how to convert the following name?

John Foo Doe => Doe, John Foo / Doe, Foo John

I'm appreciating all input on this broad question. Please list possible problems (and preferably its solution), or perhaps a project which has faced this problem before.

  • Feel free to edit the question to improve it or its language. My native language obviously isn't English ;-). – Zar Feb 8 '13 at 17:59
  • 7
    I think this is a bit outside the scope of this site, as naming practices are more a feature of culture than language. But I would also caution that there are in fact many more scenarios to consider: people with multiple middle names or multiple surnames, generational modifiers, countries where family names are given before given names, and so on. The King of Spain, commonly Juan Carlos, is fully Juan Carlos Alfonso Víctor María de Borbón y Borbón-Dos Sicilias; try parsing that :). – choster Feb 8 '13 at 18:04

This is actually a really really hard (not in the NP-hard sense) problem to solve. Consider the following examples:

All of the above are real people from the English speaking world. As you can see, it is almost impossible to find any kind of pattern in their names.

It gets worse. What if you consider titles?

Granted, for some of those, the title is easily separated from the name. I'd like to see you deal with that last one though. It gets even worse if you consider names coming from other languages. A Portuguese friend of mine is called Ana Maria Morais Sarmento de Campos. Honestly. Ana and Maria are her first names and everything else is divided into various classes of surnames.

Finally, some people have their own opinions on how their names should be written. For example, a member of this forum, Mr brian d foy, explains his own preferences very clearly here.

So, if there is any way to avoid it don't parse human names, not in English nor in any other language. It is almost impossible to formalize them. There are some workarounds and parsers available but none of them will work perfectly and their discussion is way out of scope on this site. Have a look at this post on StackOverflow for some examples.


Doe, John Foo would be correct and is used often. I have never seen "complete" reverse-name sorting where the name is listed as <last name>, <middle name> <first name>, it is always <last name>, <first name> <middle name>.

  • 3
    But "Neumann, John von" and "Márquez, Gabriel García" would be wrong (showing the perils of automating this process). – Peter Shor Feb 8 '13 at 19:11
  • 3
    Also, certain asian cultures (and maybe others) place the family name (or surname) first and the given name second. To further complicate it, they may use different orders depending on the group with which they are dealing or where they are visiting. It would be critical to find out which name is the surname, and that may not be obvious except by asking. – bib Feb 8 '13 at 19:22
  • @bib: certain European cultures (namely Hungarian) do, as well. – Peter Shor Feb 8 '13 at 20:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.