Skip to content

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

License

Notifications You must be signed in to change notification settings

gkhays/NameParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Fun Fact: There is a naming convention called a nobiliary particle which is typically used in family names to denote nobility. You may recognize some of them like von and de. Guess what? This project can extract these too!

[    ]        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.

// Considered (?<=[a-z])(?=[A-Z]).
Pattern p = Pattern.compile("(?<=[a-z])(?=[A-Z])");
Matcher m = p.matcher(s);
return m.find();

Sure enough, I quickly found one without having to get my hands too "dirty!" 😄 See "RegEx to split camelCase or TitleCase (advanced)." I tested it with the Online regex tester and debugger;

Credits & License

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages