From: "Dan Stevens (IAmAI)" Date: 2007-06-26T00:37:49+09:00 Subject: Re: Regexp to split name? > Names are just *hard* - the only reliable way of handling them that I've > found is to let users control it themselves... Agreed. My example makes very simple assumptions that I'd imagine apply to the vast majority of names. However, in many computer problems there are obscure exceptions that either break the program or break things for the user. On 25/06/07, Alex Young wrote: > dblack@wobblini.net wrote: > > Hi -- > > > > On Mon, 25 Jun 2007, Dan Stevens (IAmAI) wrote: > > > >> name = "Mr John Joe Peter Smith" > >> TITLES = ["Mr", "Mrs", "Ms", "Dr"] > >> a = name.split > >> last = a.pop > >> title = a.shift if TITLES.include? a.first > > > > Have mercy on us Yanks and allow for a period :-) > > > >> first = a.shift > >> middles = a > >> > >> title #=> "Mr" > >> first #=> "John" > >> middles #=> ["Joe", "Peter"] > >> last #=> Smith" > > > > However: > > > > name = "Mr Andrew Lloyd Webber" > > > > # etc. > > > > title #=> "Mr" > > first #=> "Andrew" > > middles #=> ["Lloyd"] (wrong) > > last #=> Webber" (wrong) > > > > name = "The Honourable Lord Andrew, the Baron Lloyd-Webber of > Sydmonton", you mean? It's hard to come up with a trickier example. > Names are just *hard* - the only reliable way of handling them that I've > found is to let users control it themselves... > > -- > Alex > >