Expression |
(?n:(^(?(?![^,]+?,)((?<first>[A-Z][a-z]*?) )?((?<second>[A-Z][a-z]*?) )?((?<third>[A-Z][a-z]*?) )?)(?<last>[A-Z](('|[a-z]{1,2})[A-Z])?[a-z]+))(?(?=,)(, (?<first>[A-Z][a-z]*?))?( (?<second>[A-Z][a-z]*?))?( (?<third>[A-Z][a-z]*?))?)$)
|
Description |
Regular expression for validating a person's full name. Matches on two general formats: 1) first second third last (where first, second, and third names are optional and all present are separated by a space); 2) last, first second third (where second and third are optional, last is followed immediately by a comma and a space, and second, and third, if present, are separated by a space from each other and from first). First corresponds to surname and last corresponds to family name. Each name part is captured to a named group to facilitate program manipulation. Each name part must begin with an uppercase letter, followed by zero or more lowercase letters, except for the last name. Last name must begin with an uppercase letter, followed by one or more lowercase letters, but will match exceptions formatted like the following: McD..., MacD..., O'R... Only format is validated, not spelling. NOTE: This regular expression uses positive and negative regex lookahead to determine the general format of the name, i.e. the presence or the absence of the comma determines the general format that will match. Furthermore, this initial version is not designed to accommodate titles and things like "3rd".
|