code_junkie

Simple way to parse a person's name into its component parts?

Nov 11th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. Name = Name.Trim();
  2.  
  3. arrNames = Name.Split(' ');
  4.  
  5. if (Name.Length > 0) {
  6. GivenName = arrNames[0];
  7. }
  8. if (Name.Length > 1) {
  9. FamilyName = arrNames[arrNames.Length - 1];
  10. }
  11. if (Name.Length > 2) {
  12. MiddleName = string.Join(' ', arrNames, 1, arrNames.Length - 2);
  13. }
  14.  
  15. /^ s*
  16. (?:((?:Dr.)|(?:Mr.)|(?:Mr?s.)|(?:Miss)|(?:2ndsLt.)|(?:Sen.?))s+)? # prefix
  17. ((?:w+)|(?:w.)) # first name
  18. (?: s+ ((?:w.?)|(?:ww+)) )? # middle initial
  19. (?: s+ ((?:[OD]['’]s?)?[-w]+)) # last name
  20. (?: ,? s+ ( (?:[JS]r.?) | (?:Esq.?) | (?: (?:M)|(?:Ph)|(?:Ed) .?s*D.?) |
  21. (?: R.?N.?) | (?: I+) ) )? # suffix
  22. s* $/x
  23.  
  24. Name Parts | Correct | Percent of Names in DB
  25. 2 100% 48%
  26. 3 98% 42%
  27. 4 70% 9%
  28. 5 45% 0.25%
Add Comment
Please, Sign In to add comment