RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(?<FirstName>[A-Z]\.?\w*\-?[A-Z]?\w*)\s?(?<MiddleName>[A-Z]\w*|[A-Z]?\.?)\s?(?<LastName>[A-Z]\w*\-?[A-Z]?\w*)(?:,\s|)(?<Suffix>Jr\.|Sr\.|IV|III|II|)
Description
A regex that attempts to accurately parse the elements from a proper name where the format is in &lt;&lt;First, Last&gt;&gt; order or some permutation of that order. Critiques and suggestions for improvement are welcome.
Matches
David F Walker | J. S. Smith, Jr. | Catherine Zeta-Jones
Non-Matches
oscar peterson
Author Rating: The rating for this expression. David Walker
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Suggestion
Name: Philippe Dykmans
Date: 11/26/2010 8:42:48 PM
Comment:
Hi, Very useful pattern (for me). It would be even nicer if one could somewhere enumerate those prefixes that typically go with the last name. Like: 'de' (Helene de Fougerolles) 'de la' (Astrid de la Vega) 'van de' (Monique van de Ven) 'di' (Leonardo di Caprio) It's probably quite easy. But i'm not so familiar with Regex. Regards, Philippe ([email protected])


Title: Thanks!
Name: Nick
Date: 1/20/2005 2:58:27 AM
Comment:
Thanks- I used this as a base for parsing names of an automated book scanning program. Lots of the author names didn't have a middle initial, and I made some other changes: (?<FirstName>[A-Z]\.?\w*\-?[A-Z]?\w*)\s? (?<MiddleName>\b[A-Z]\w*|[A-Z]?\.?)\s? (?<LastName>\b[A-Z]\w*\-?[A-Z]?\w*) (?:,?\s|) (?<Suffix>D\.?D\.?S\.?|[DJS]r\.$|[MOD]\.?D\.?|[IVX]+|) Will now also match: David Walker Catherine Zeta-Jones, M.D. Fred Made-Up, DDS. King George, VIII


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials