0

I've been creating a regex to catch a person's name from a larger chunk of tex twith this following format:

Last Name, First Name and Additional Names (2 Additional Names Maximum)
No Additional special characters except for comma (,)
Only Names that can be derived from English alphabet [A-Z]|[a-z]

Example of Format Name:

Johnson, Carl
Scott, Michael Mark
Smith, Robert Angelo John

  1. The first Example contains only Last Name and First Name
  2. The second Example contains Last Name, First Name and Additional Name
  3. The third Example contains Last Name, First Name and two Additional Names

So far, I've been on trial and error in Regex and this is my current regex:

^([A-z]|[a-z])*[,][\s]*([A-z]|[a-z]|[\s])*
  • When you say “catch”, you mean fish those out of a larger chunk of text? Or do you just want to split the exact values you have shown into their “parts”? – 04FS Jan 15 '20 at 15:05
  • 4
    I would suggest **not** doing this, you'll only fall foul of *Bill S. Preston esq.* or *周潤發* - names aren't as regular as you'd think. Just let people use whatever the heck they want as names, much as anyone with a tenner and five minutes to spare can do to change their name by deed poll. – CD001 Jan 15 '20 at 15:07
  • @CD001 Only names that can be derived from English Alphabet. –  Jan 15 '20 at 15:12
  • @04FS yes that is what I am trying to do, get the detected name from a larger chunk of text –  Jan 15 '20 at 15:13
  • WHY should one want to validate person names? – B001ᛦ Jan 15 '20 at 15:16
  • @B001ᛦ not validate, just a detection would be enough –  Jan 15 '20 at 15:18
  • 1
    _just a detection would be enough..._ What about a "name" like "Dog, Cat" ? – B001ᛦ Jan 15 '20 at 15:19
  • 1
    I like to refer back to [this blog post](https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/) whenever someone tries to RegEx names... – CD001 Jan 15 '20 at 15:23

0 Answers0