ID EN
#Dynamic array

REGEXTEST

Excel Functions

Test a value for a specific pattern of text

Syntax

EXCEL
=REGEXTEST(text, pattern, [case_sensitivity])

Arguments

Parameter Description
text The text value to test.
pattern The pattern to test for.
case_sensitivity [optional] 0 = Case sensitive, 1= Case-insensitive. Default is 0.

Return Value

TRUE or FALSE

Details

The REGEXTEST function provides a way to test for specific text defined by a "regex" pattern. The result from REGEXTEST is TRUE or FALSE. You can think of REGEXTEST as a major upgrade to simpler functions like FIND and SEARCH, which can be used to test a cell for specific text. While these functions can perform primitive tests – FIND is case-sensitive but does not support wildcards, SEARCH supports wildcards but is not case-sensitive – they are no match for REGEXTEST, which can define tests using the full power of regular expressions. With regex, you can easily test for numbers, upper and lower case letters, exact quantities of certain characters, and for specific character sequences that follow a pattern. To use REGEXTEST, provide text and a pattern. For example, the formulas below show h

Examples

Code example

To use REGEXTEST, provide text and a pattern. For example, the formulas below show how REGEXTEXT can be used to test the text in A1 for a number or an

EXCEL
=REGEXTEST(A1,"[0-9]") // test for a number
=REGEXTEST(A1,"[A-Z]") // test for an uppercase character
Code example

REGEXTEST returns TRUE or FALSE. If we use REGEXTEST to test for "a" in "apple", it returns TRUE:

EXCEL
=REGEXTEST("apple","a") // returns TRUE
Code example

If we use REGEXTEST to test "apple" for a single digit between 0-9, it returns FALSE:

EXCEL
=REGEXTEST("apple","[0-9]") // returns FALSE
Worksheet example

The worksheet below uses REGEXTEST to test the same string, "1apple23#z", with twelve different patterns. In each formula, the text string comes from

EXCEL
=REGEXTEST(B5,D5)
Worksheet example

Let's review the formulas one by one. Note that the formulas below use literal strings instead of cell references for readability. In each case, the t

EXCEL
=REGEXTEST("1apple23#z","apple") // returns TRUE
Worksheet example

REGEXTEST returns TRUE because the literal string "apple" appears in the text. Note that REGEXTEST automatically performs a "contains" type search.

EXCEL
=REGEXTEST("1apple23#z","a") // returns TRUE

See Also

REGEXEXTRACT REGEXREPLACE FIND SEARCH