0

I have the following Google Spreadsheet.

Google Spreadsheet

When users enter a name into any cell of column A of the sheet named "Unit Standards" I want them to enter that name in a particular format. That is, with the surname first in uppercase then a comma, then the first name in title case then if they are known by a different name that name to be title case in brackets e.g.

  • BUSH, George
  • TRUMP, Donald
  • CLINTON, William (Bill)
  • CARTER, James (Jimmy)
  • SMITH-JONES, John
  • ZETA-JONES, Catherine (Kate)

Someone else helped me with the following code which I have added to column A as a Data Validation.

=REGEXMATCH(A10,"^[A-Z]+\b[',']\s[A-Z]{1}[a-z]+\b(\s([A-Z][a-z]+\b))?$")

You can see by the following image that some of the inputs are in violation so the formula is not quite right.

Data Validation

I would appreciate some help with the code.

2 Answers 2

2

This regex matches all the cases you proposed:

[A-Z][A-Z' ]+(-[A-Z' ]+)*, [A-Z][a-z]+( \([A-Za-z]+\))?

enter image description here

EDIT: Added the cases proposed in comment.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you - it now works for every possibility except ZETA-JONES, Catherine (Kate)
Is because zeta-jones have a dot.
Now it includes the dot
I'm impressed - that works perfectly. Thank you very much for your time and input.
Sorry - I have come across another 3 scenarios TE AMO, Eric, also O'BRIEN, Patrick and SMITH, Carl (CJ)..Would you mind helping me with these? And sorry again, the dot was a mistake
1

try:

=ARRAYFORMULA(REGEXMATCH(A1:A10, "^([A-Z' -]+), ([A-Z]{1}[a-z]+)( \([A-ZA-z]+\))?$"))

0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.