dimanche 19 avril 2015

Regex to match middle name/s

Assume input of a string containing a full name. Full names are very diverse - ie. Joe Bloggs, Joe Bloggs-Phillips, Joe Bloggs Phillips, Joe Bloggs Adams Phillips, Joe van den Bloggs, Joe van-der Bloggs.


I want to match what I will call "middle names". That is everything between the first and last space. That is, as above - "Bloggs Adams", "van den" and "van-der". Names with hyphenated words are full surnames. What is the regex for this?


PS. I'm aware of the cultural diversity in names, eg. "van der" is not actually a middle name but the start of a surname. So, if there is logic to build in to this regex to accommodate, this would help. Otherwise, I want to assume:



  • First name - everything up to first space.

  • Middle name - from first space to last space.

  • Last name - from final space to end.


Many thanks.


Aucun commentaire:

Enregistrer un commentaire