Count cells that match a regex
=SUMPRODUCT(--REGEXTEST(A2:A11,D1))Excel · result on the sample sheet: 5
Describe what you need and get a working REGEXTEST formula for Excel and Google Sheets, tested on real data before you copy it. REGEXTEST checks whether text contains a match for a regular expression and returns TRUE or FALSE.
Each formula below was calculated on its own sample sheet. Open one to see the sheet, why it works, and to try it yourself.
=SUMPRODUCT(--REGEXTEST(A2:A11,D1))Excel · result on the sample sheet: 5
=FILTER(A2:B9,REGEXMATCH(A2:A9,E1))Google Sheets · result on the sample sheet: 5 rows (E2:F6)
=IF(REGEXMATCH(A2,"^\d{5}(-\d{4})?$"),"Valid","Check")Google Sheets · result on the sample sheet: 7 rows (B2:B8)
=REGEXTEST(A2,"^\d+$")Excel · result on the sample sheet: 6 rows (B2:B7)
=REGEXTEST(A2,"^[^@\s]+@[^@\s]+\.[A-Za-z]{2,}$")Excel · result on the sample sheet: 7 rows (B2:B8)
=REGEXTEST(A2,"^[A-Z]{3}-\d{4}$")Excel · result on the sample sheet: 6 rows (B2:B7)
You describe the task in plain English, and it writes the formula, using REGEXTEST where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.
REGEXTEST checks whether text contains a match for a regular expression and returns TRUE or FALSE.
Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the REGEXTEST function page has a practice exercise.