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

ArgumentRequired?What it does
textYesThe text to check.
patternYesThe regular expression, in quotes.
case_sensitivityOptional0 = 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}$")
AB
1SKUValid?
2NS-1042TRUE
3NS-104FALSE
4ns-1042FALSE
5NS-10421FALSE
=REGEXTEST(A2, "^NS-\d{4}$") Explain
  1. ^ means the start of the text and $ the end, so nothing extra is allowed.
  2. \d{4} means exactly four digits.
  3. Lowercase “ns” fails because matching is case-sensitive by default.

Example 2 — Ignoring case

Accept ns-1042 as well.

=REGEXTEST(A2, "^NS-\d{4}$", 1) Explain

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.
Kyle Stott

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.