Premium Google Sheets drill · Text and regular expressions
REGEXMATCH product codes
Practice Google Sheets REGEXMATCH inside ARRAYFORMULA to test codes shaped like two letters, a hyphen, and four digits.
A code is valid when it is two capital letters, a hyphen, and four digits, such as AB-1044. REGEXMATCH returns TRUE or FALSE.
In B2, test A2:A4 with ARRAYFORMULA and REGEXMATCH. The pattern is case-sensitive.
Dataset
Starter sheet. Cells marked formula are where the formula goes.
| Row | A | B |
|---|---|---|
| 1 | Code | |
| 2 | AB-1044 | Formula goes in B2. formula |
| 3 | ab-1044 | |
| 4 | A-1044 |
Hint
Use the pattern ^[A-Z]{2}-\d{4}$ with one backslash before the d.
Explanation
AB-1044 matches. ab-1044 fails because [A-Z] does not include lowercase, and A-1044 has only one letter. The three results spill from B2.
The interactive sheet and a worked solution are part of Formula Drills Premium. The instructions and starter data on this page are the full problem.