Back to functions
Text2026-11-111 related article

REGEXTEST Function in Excel

Check whether text matches a regular expression and return TRUE or FALSE.

Syntax

REGEXTEST(text, pattern, [case_sensitivity])
Table of Contents

Arguments

text

Required

The text or cell reference to check.

pattern

Required

The PCRE2 regular expression describing the text to match.

case_sensitivity

Optional

Use 0 or omit for case-sensitive matching; use 1 to ignore case.

What it returns

Returns TRUE if the pattern matches any part of the text, or FALSE if there is no match.

What REGEXTEST does

REGEXTEST checks text against a pattern and returns a logical TRUE or FALSE. Use it to flag product codes with the wrong format or to find a matching fragment in a description. It leaves the original text intact.

A match anywhere in the text is enough unless your pattern requires the whole value to match. Microsoft's REGEXTEST reference documents PCRE2 as its regular expression syntax.

Practical examples

Find a code inside a description

Put X AB-0012 old in A6:

=REGEXTEST(A6,"[A-Z]{2}-[0-9]{4}")
Formula

The result is TRUE. The pattern finds two uppercase ASCII letters, a hyphen, and four digits in AB-0012. It doesn't reject the surrounding words.

Require the entire value to be a code

Keep A6 as X AB-0012 old and put AB-0012 in A5. Test A6 with:

=REGEXTEST(A6,"\A[A-Z]{2}-[0-9]{4}\z")
Formula

The result is FALSE. Changing A6 to A5 in this formula returns TRUE. The \A and \z markers require the match to begin and end with the entire text, so extra words or spaces fail the check.

Allow lowercase only when the rule permits it

Put ab-0012 in A7:

=REGEXTEST(A7,"\A[A-Z]{2}-[0-9]{4}\z",1)
Formula

The result is TRUE because the final argument turns off case sensitivity. Omitting it, or using 0, returns FALSE for the same lowercase code. This setting changes the comparison; it doesn't uppercase A7.

Common mistakes and notes

A partial match is different from validation

Use whole-text markers when every character must follow the rule. In PCRE2, \z is the absolute end of the text; $ can also match before a final newline. The PCRE2 assertion documentation explains the distinction. Use a single backslash before A and lowercase z in the Excel formula.

With AB-0012 in A5, =REGEXTEST(A5&CHAR(10),"\A[A-Z]{2}-[0-9]{4}\z") returned FALSE in Excel for Mac 16.114 (build 16.114.26101123) on November 11, 2026. Changing the pattern to ^[A-Z]{2}-[0-9]{4}$ returned TRUE for the same final line break. The absolute end marker keeps that unwanted character from passing the check.

A matching format doesn't prove the code exists

ZZ-9999 passes this pattern whether or not it appears in your catalog. Use a separate lookup to check membership. For a case-sensitive comparison against one exact value, see EXACT.

TRUE and FALSE are logical values

You can pass the result to IF to display a review label. To return the matching code itself, use REGEXEXTRACT. Microsoft currently lists REGEXTEST for Excel for Microsoft 365 and Excel for Microsoft 365 for Mac.

Related functions

Related articles

Deep dives, troubleshooting guides, and practical examples that use REGEXTEST.

Official documentation