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)."
- Based on the PHP-Name-Parser by Josh Fraser.
- Ported to Java by Garve Hays.
- Released under the Apache 2.0 License.