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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Full Name - Supports hyphens and apostrophes
Expression
^(?-i:[A-Z]{1}[a-z]+(?<fnh>[-]{1})?(?(fnh)[A-Z]{1}[a-z]+)\s[A-Z]{1}(?<apos>[']{1})?(?(apos)[A-Z]{1})[a-z]+(?<lnh>[-]{1})?(?(lnh)[A-Z]{1}[a-z]+))$
Description
This pattern allow a first and last name to be tested to ensure that each name begins with a capital letter and is separated by just one space. The pattern also ensures that only one hyphen can be placed in either the first or last name and the succeeding character must be capitalized. If an apostrophe is used in the last name it too must be succeeded by a capital letter.
Matches
Anne-Marie O’Conner-Smith | Anne Smith | Mary-Jo O’Conner | Mary Smith-Kline
Non-Matches
Anne--Marie Smith | Mary OConner | Mary-jo Wilson
Author Rating: Not yet rated. Philip Ragan
Source While I developed this pattern mostly through experimentation, I was guided by various articles including those on http://www.regular-expressions.info
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

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