2

I'm trying to formulate a data validation code in Google Sheets for a simple 6-letter string - any 3 capital letters and any 3 lowercase letters. I believe I should be using the RegexMatch function. Here's what I tried:

=RegexMatch("[A-Z][A-Z][A-Z]\\[a-z][a-z][a-z]")

But when I try to type AAAaaa in the cell it rejects it.

0

1 Answer 1

1

The formula is invalid because it lacks a range reference. In addition, the regex has a superfluous backslash \.

To validate a range whose top-left cell is A2, use this rule:

=regexmatch(A2, "^[A-Z]{3}[a-z]{3}$")

The rule will match when the value in the cell starts with exactly three uppercase English letters, ends with exactly three lowercase English letters, and contains nothing else.

To match strings that contain three uppercase letters followed by three lowercase letters, and may contain other text as well, remove the ^ and $.

To learn the exact regular expression syntax used by Google Sheets, see RE2.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.