Reputation: 29
I am trying to build a regex that fulfills these requirements, but I am not sure how to do it. I tried with:
[A-Z][a-z]+[,][ ][A-z][a-z]+($|[[ ]{0,1}[A-Z][.]]{0,1})
but it's not doing what I want. I need some help.
Requirements
Last, First M.
Last - must begin with a capital letter and be followed by one more lower case letters.
First - must begin with a capital letter and be followed by one or more lower case letters.
M. - must be a single capital letter followed by a period (.). This part (including the preceding space) is optional.
Examples of valid accepted strings are:
"Davis, Mike"
"Leppla, David A."
Invalid examples are:
"D, Mike"
"L, David"
"Smith, Joe " (with an extra space on the end)
"smith, Mike"
"Jo, Fr a."
Upvotes: 0
Views: 75
Reputation: 6526
I suggest you the following regex to be compliant with your requirements:
[A-Z][a-z]+, [A-Z][a-z]+( [A-Z]\.)?
Upvotes: 1