# How to check if text matches a pattern in Excel

Use REGEXTEST in Excel 365: =REGEXTEST(A2,"^[A-Z]{3}-\d{4}$") checks for three capital letters, a dash and four digits. Google Sheets uses REGEXMATCH.

**Excel:** `=REGEXTEST(A2,"^[A-Z]{3}-\d{4}$")` (Microsoft 365 only)

**Google Sheets:** `=REGEXMATCH(A2,"^[A-Z]{3}-\d{4}$")`

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| SKU | Valid? |
| NWD-1042 |  |
| nwd-1042 |  |
| NWD-104 |  |
| NW-1042 |  |
| ABC-0031 |  |
| NWD1042 |  |

Formula in B2, filled to B7: `=REGEXTEST(A2,"^[A-Z]{3}-\d{4}$")`

Result: TRUE; FALSE; FALSE; FALSE; TRUE; FALSE

## How it works

`[A-Z]{3}` means exactly three capital letters, `-` a dash, `\d{4}` exactly four digits, and `^` and `$` pin the pattern to the start and end, so nothing extra is allowed. REGEXTEST is case-sensitive by default, so "nwd-1042" fails.

## Other ways

- `=AND(LEN(A2)=8,MID(A2,4,1)="-",ISNUMBER(--RIGHT(A2,4)),EXACT(LEFT(A2,3),UPPER(LEFT(A2,3))))`: Works in every version: checks the length, the dash, the digits and the capitals one by one. It doesn't check that the first three are letters.

## Common mistakes

- Without ^ and $, "XNWD-10420" passes because the pattern is found inside it.
- REGEXTEST is only in Microsoft 365. Older versions show #NAME?; use the AND version there.

## Questions

**How do I make the match ignore case?**

Set the third argument to 1: `=REGEXTEST(A2,"^[A-Z]{3}-\d{4}$",1)`. In Google Sheets, start the pattern with `(?i)`.

**Can I use this to block bad entries?**

Yes. Use it as a custom Data Validation formula for the column.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/check-if-text-matches-a-pattern
