Skip to content

REGEXTEST

Checks whether text matches a regular expression pattern and returns TRUE or FALSE.

Syntax

=REGEXTEST(, , )

TextStatic examples

Excel for Microsoft 365 only, and only on builds that include it. Microsoft has rolled out the REGEX functions in stages by update channel, so on a build without them the formula returns #NAME?. Not available in Excel 2024 or earlier. The practice sheet on this page cannot run REGEXTEST yet.

How REGEXTEST works

REGEXTEST checks whether text matches a pattern written as a regular expression, and returns TRUE or FALSE. A regular expression describes the shape of text instead of listing exact characters: "two capital letters, a dash, four digits" rather than a fixed code. It is the tool for validating codes, spotting formats and finding text that follows a rule.

Availability

REGEXTEST is one of three REGEX functions added to Microsoft 365, together with REGEXEXTRACT and REGEXREPLACE. Microsoft released them in stages, so some Microsoft 365 builds have them and some do not yet. On a build without them, Excel shows #NAME?. They are not in Excel 2024 or earlier. If a workbook must open everywhere, use the older approach, covered at the end of this page.

The practice sheet on this page runs Rangewise's own formula engine, which does not support the REGEX functions yet. The examples below show the results Excel gives. The exercise uses the older functions to solve the same kind of problem.

The arguments

  • text is what to test.
  • pattern is the regular expression, in quotes.
  • case_sensitivity is optional. The default, 0, is case-sensitive, which differs from SEARCH. Use 1 to ignore case.

A short pattern guide

| Pattern | Meaning | |---|---| | \d | One digit | | [A-Z] | One capital letter | | {4} | Exactly four of the previous item | | + | One or more | | . | Any single character | | ^ and $ | Start and end of the text | | \s | A space or other whitespace |

=REGEXTEST(A2,"^[A-Z]{2}-\d{4}$") is TRUE for FX-1010 and FALSE for fx-1010 (case), FX-10 (too short) and FX-1010X (extra text).

Anchors matter

Without ^ and $, a match anywhere counts. =REGEXTEST("Order FX-1010 shipped","[A-Z]{2}-\d{4}") is TRUE, because the pattern is found inside the text. Add the anchors when the whole value must have the shape.

Not the same as wildcards

Patterns look like the wildcards of SEARCH and COUNTIF but mean something else. In a regular expression, * repeats the previous item and . stands for any character, whereas the wildcard ? means one character. Don't copy patterns between them.

Older approach

Without REGEX, tests like these combine LEN, LEFT, EXACT, ISNUMBER with SEARCH or FIND. They work in every version, take more formula, and cope less well with complicated shapes.

Arguments

text
The text to test. Usually a cell such as A2.
pattern
The regular expression to look for, in quotes, such as "^[A-Z]{2}-\d{4}$". Unless the pattern is anchored with ^ and $, a match anywhere in the text counts.
case_sensitivityoptional
0, the default, is case-sensitive. 1 ignores case.

Examples

Example 1

Validate a code format

C2 =REGEXTEST(A2,"^[A-Z]{2}-\d{4}$")

Result: TRUE

Two capital letters, a dash and four digits, with nothing else. This is what Excel returns; the practice sheet here cannot run the function yet.

Shown as a static example: our practice sheet doesn't calculate this function yet.

Example 1: Validate a code format
RowABC
1Entered codeOwnerValid?
2FX-1010FinanceTRUE
3fx-1085Planning
4
5

Example 2

Case-sensitive by default

C3 =REGEXTEST(A3,"^[A-Z]{2}-\d{4}$")

Result: FALSE

The lower-case letters don't match [A-Z] when matching is case-sensitive, which is the default.

Shown as a static example: our practice sheet doesn't calculate this function yet.

Example 2: Case-sensitive by default
RowABC
1Entered codeOwnerValid?
2FX-1010Finance
3fx-1085PlanningFALSE
4
5

Example 3

Ignore case with the third argument

C3 =REGEXTEST(A3,"^[A-Z]{2}-\d{4}$",1)

Result: TRUE

case_sensitivity 1 lets [A-Z] match lower-case letters too.

Shown as a static example: our practice sheet doesn't calculate this function yet.

Example 3: Ignore case with the third argument
RowABC
1Entered codeOwnerValid?
2FX-1010Finance
3fx-1085PlanningTRUE
4
5

Example 4

Does the text contain a digit?

C2 =REGEXTEST(A2,"\d")

Result: FALSE

Without anchors, the pattern is found anywhere in the text. "Pallet wrap" has no digit, so the result is FALSE.

Shown as a static example: our practice sheet doesn't calculate this function yet.

Example 4: Does the text contain a digit?
RowABC
1DescriptionQtyHas a digit?
2Pallet wrap38FALSE
3
4
5

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

The REGEX functions can't run in this sheet yet, so do the check the older way. In B2, return TRUE if the code in A2 is exactly 7 characters and starts with FX- in capitals. Fill it down to B5.

=AND(LEN(A2)=7,EXACT(LEFT(A2,3),"FX-"))

In C2, return TRUE if the last four characters of A2 are all digits, and FALSE otherwise. Fill it down to C5.

=ISNUMBER(--RIGHT(A2,4))

Common mistakes

  • REGEXTEST isn't in every version of Excel. Where it is missing the formula returns #NAME?. Check which version people will use before you rely on it.
  • Matching is case-sensitive by default, unlike SEARCH. Set the third argument to 1 to ignore case.
  • Without ^ and $, a match anywhere in the text returns TRUE. Anchor the pattern when the whole value must match.
  • Regular expressions are not wildcards. * means "repeat the previous item" and . means "any one character". Patterns written for COUNTIF or SEARCH need rewriting.
  • A pattern that isn't valid regular-expression syntax returns an error instead of FALSE. Test patterns on a few known values.

Questions people ask

Does Excel support regular expressions?

Yes, in Microsoft 365 builds that include the REGEX functions: REGEXTEST, REGEXEXTRACT and REGEXREPLACE. Earlier versions, including Excel 2024, don't have them.

Why does REGEXTEST return #NAME?

Your version of Excel doesn't have the function yet. It is Microsoft 365 only and has rolled out in stages by update channel. Use the older text functions or update your build.

Is REGEXTEST case-sensitive?

By default, yes. Add 1 as the third argument to ignore case.

How do I check that a code matches a format without regular expressions?

Combine LEN, LEFT, MID and EXACT, for example `=AND(LEN(A2)=7,EXACT(LEFT(A2,3),"FX-"))`. It works in every version, but gets long for complicated patterns.

What is the difference between REGEXTEST and SEARCH?

SEARCH finds a fixed piece of text, with the simple wildcards ? and *, and returns its position. REGEXTEST matches a pattern and returns TRUE or FALSE.

Learn REGEXTEST in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.