joshfraser / NameParser

Parses a name into various parts including honorific, first name, initial, last name, and suffix.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NameParser

Parses a name into various parts including:

  • Honorific
  • First name
  • Middle initial
  • Last name
  • Suffix

Ported from php-name-parser. See also Splitting names.

[    ]        Von |       Fabella [    ]
[    ]     Pitney | E.      Bowes [    ]
[    ]        Dan |        Rather [    ]
[    ]         Dr |         Jones [    ]
[    ]     Marcus |         Welby [  MD]
[    ]        Ken |       Griffey [ Jr.]
[    ]       Jack |         Jones [M.D.]
[    ]   Pluribus | E.       Unum [    ]
[    ]        Don | R.     Draper [    ]
[    ]    William | S.      Gates [  SR]
[    ]    William | S.      Gates [ III]
[    ]         La |        Alpaca [    ]
[    ]     Murray | F.    Abraham [    ]
[ Mr.]        Ted |        Knight [Esq.]
[    ]       June |       Cleaver [    ]
[ Mr.]     Robert |         Jones [    ]
[    ]    Cynthia |         Adams [    ]

PHP has a handy ucfirst utility that is used in the original implementation. It turns out a Java implementation has already been discussed on StackOverflow in the article "How to capitalize the first letter of word in a string using java?."

The PHP code uses a conditional statement and a regular expression to look for words in Pascal Case such as McDonald.

function is_camel_case($word) {
    if (preg_match("|[A-Z]+|s", $word) && preg_match("|[a-z]+|s", $word)) 
        return true;
    return false;
}

However, I thought I could get the match in a single regular expression. Sure enough, I quickly found one without having to get my hands dirty with the Online regex tester and debugger; see "RegEx to split camelCase or TitleCase (advanced)."

Credits & License

About

Parses a name into various parts including honorific, first name, initial, last name, and suffix.


Languages

Language:Java 100.0%