REGEXTEST Function
Checks whether text matches a regular expression pattern.
Category
Text
Available in
Microsoft 365
Returns
TRUE or FALSE
Want to practice REGEXTEST in a real spreadsheet? Open a blank sheet in our Practice Sandbox and try it with live data, with the AI Excel tutor beside you. No Excel needed — just a free account.Try it free in the Sandbox
Overview
REGEXTEST answers “does this text fit the pattern?” using regular expressions — a mini-language for describing text, such as \d{4} for four digits.
It's ideal for validating codes, emails and phone numbers that must follow a format.
Syntax
=REGEXTEST(text, pattern, [case_sensitivity])
Arguments
| Argument | Required? | What it does |
|---|---|---|
| text | Yes | The text to check. |
| pattern | Yes | The regular expression, in quotes. |
| case_sensitivity | Optional | 0 = case-sensitive (default), 1 = ignore case. |
Examples
Example 1 — Validating SKUs
A valid Northstar SKU is NS, a dash and exactly four digits.
B2fx=REGEXTEST(A2, "^NS-\d{4}$")
| A | B | |
|---|---|---|
| 1 | SKU | Valid? |
| 2 | NS-1042 | TRUE |
| 3 | NS-104 | FALSE |
| 4 | ns-1042 | FALSE |
| 5 | NS-10421 | FALSE |
=REGEXTEST(A2, "^NS-\d{4}$") Explain
- ^ means the start of the text and $ the end, so nothing extra is allowed.
- \d{4} means exactly four digits.
- Lowercase “ns” fails because matching is case-sensitive by default.
Common mistakes
- Forgetting ^ and $. Without them, the pattern can match part of the text: "NS-10421" contains NS-1042.
Notes
- Handy tokens: \d digit, \w letter/digit/underscore, \s space, . any character, + one or more, * zero or more, {n} exactly n.
- Related functions: REGEXEXTRACT, REGEXREPLACE, SEARCH.

Author
Kyle Stott
Certified Microsoft Excel Expert
Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.