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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(^((?<salutation>[MRD]\S+)[ ]+)?(?<first>\S+)[ ]+((?<middle>\S+)[ ]+)??(?<last>\S+)([ ]+(?<suffix>(PHD|MD|RN|JR|II|SR|III)))?)
Description
Parses a person's name such as MR KENNETH L LEFEBVRE PHD, allowing for optional salutation, middle name, and suffix. NOTE: The suffix must be one of a hard-coded list of suffixes.
Matches
DR KENNETH L LEFEBVRE PHD | KEN LEFEBVRE | K L LEFEBVRE | KENNETH LEFEBVRE PHD | DR KENNETH LEFEBVRE
Non-Matches
Author Rating: The rating for this expression. Kenneth LeFebvre
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: Error?
Name: N/A
Date: 8/10/2010 8:33:47 PM
Comment:
I put this into the Regex Tester with the sample you gave "DR KENNETH L LEFEBVRE PHD" and it did not work


Title: re: Not intended for validation
Name: Kenneth LeFebvre
Date: 7/15/2004 4:53:04 PM
Comment:
Interesting... its working in my code. When I get a moment I'll have to double-check that I uploaded the correct pattern...


Title: re: Not intended for validation
Name: Michael Ash
Date: 7/15/2004 4:18:32 PM
Comment:
The name captures are not going to get values you maybe trying to get. As it's posted now <middle> will never have a value. You have one too many ?'s after the group. Removing one will fix that but the captures still won't always be right. For Example "Mickey D Mouse JR" will capture : <salutation> = Mickey <first> = D <middle> = Mouse <last> = JR <suffix> {EMPTY}


Title: Not intended for validation
Name: Kenneth LeFebvre
Date: 7/15/2004 11:11:54 AM
Comment:
True... I'm not using this to validate names, but merely to split them into components.


Title: Very lax
Name: Michael Ash
Date: 7/15/2004 10:04:31 AM
Comment:
While parsing names will never be 100% this expression is way too lax. It will accept almost anything.All of the following match @@@@@@ ###### Re: Good Morning! $3,000,000 JR Also the middle capture group won't be populated


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