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.