Table of Contents
Excel's regex functions handle text patterns: REGEXTEST returns TRUE or FALSE, REGEXEXTRACT returns matching text, and REGEXREPLACE changes matched text. Use them when a pattern is more useful than a fixed word or delimiter.
They are available in supported Microsoft 365 Excel versions. Check your edition and update channel if you receive #NAME?. The examples use commas; your regional settings may require semicolons.
Regex building blocks
| Pattern | Meaning |
|---|---|
^ and $ | Start and end of the text. |
. | Any character except a newline under ordinary matching. |
[0-9] | One digit; the hyphen defines a range inside a character class. |
[A-Za-z0-9] | One ASCII letter or digit. Capitalization matters in ranges. |
[^0-9] | One character that is not a digit. |
* and + | Zero or more, or one or more, repetitions of the preceding token or group. |
() | A capturing group. |
{3} and {3,} | Exactly three, or at least three, repetitions. |
For example, a{3,} matches aaa or a longer run of a's, not a or aa. Excel uses the PCRE2 regex flavor; syntax from another spreadsheet tool is not always interchangeable.
REGEXTEST: check whether text matches
=REGEXTEST(text,pattern,[case_sensitivity])The optional case setting is 0 for case-sensitive matching (the default) or 1 for case-insensitive matching. It is not an “i” string argument.
| Formula | Expected behavior |
|---|---|
=REGEXTEST(A2,"[0-9]{3}") | TRUE for PRD-12345-X because it contains three consecutive digits. |
=REGEXTEST(A2,"^[0-9]{3}$") | TRUE only when the entire text is exactly three digits. |
=REGEXTEST(A2,"^pro",1) | Matches a prefix such as pro or PRO, ignoring case. |

The pattern d{3} would look for three literal d characters. Use [0-9]{3} when you mean three digits.
A limited email-format check
=REGEXTEST(B3,"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,}$")
This is a basic format screen, not complete email-address validation. It does not prove a mailbox exists or can receive messages, and it does not cover every valid address form. [.] matches a literal dot; an unescaped dot would match almost any character.
REGEXEXTRACT: return matching text
=REGEXEXTRACT(text,pattern,[return_mode],[case_sensitivity])Return mode 0 gives the first match, 1 gives all matches as an array, and 2 gives capturing groups from the first match. Leave enough empty cells for array results.
=REGEXEXTRACT(B3,"^[^@]+")
For john.doe@example.com, this returns john.doe. It extracts the leading non-@ text; it does not validate the whole address.
=REGEXEXTRACT(B2,"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,}")
This extracts the first email-like substring from B2. Use the actual source cell in your sheet. If all you need is text before a fixed @ delimiter, a simpler text function may be easier to maintain.
REGEXREPLACE: replace matched text
=REGEXREPLACE(text,pattern,replacement,[occurrence],[case_sensitivity])Occurrence 0, the default, replaces all matches. A positive occurrence selects that match; negative values count from the end.
=REGEXREPLACE(B3,"^[^@]+","jane.doe")
With the same example input, the result is jane.doe@example.com. The formula returns new text; it does not modify B3.
=REGEXREPLACE(C2,"[^0-9]","")
This retains only digits from C2. For phone data, it also removes the plus sign and extension labels, so do not use it as a universal international-phone normalizer. Keep the original and preserve leading zeros as text.
Combine a test with IF
=IF(REGEXTEST(B3,"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,}$"),"Matches basic format","Review format")

The labels describe a pattern check without claiming an address is deliverable. Test valid-looking, invalid, blank, and unusual inputs before filling formulas down a large dataset. Screenshots illustrate the workflow; use the corrected formulas printed above.
Consult Microsoft's REGEXTEST, REGEXEXTRACT, and REGEXREPLACE references for optional arguments. For simpler operations, see Excel text functions and IF examples.
Reader Comments 0
Sign in with email or Google to join the discussion.