Formulas & Functions•5 min read
Excel REGEX Functions: REGEXTEST, REGEXEXTRACT, REGEXREPLACE
Learn REGEX functions in Excel. Use REGEXTEST, REGEXEXTRACT, and REGEXREPLACE to match text patterns without VBA.
SheetHub••5 min
Matching text patterns in Excel used to mean learning VBA or hunting for third-party add-ins. That changed with the introduction of native REGEX functions.
Excel now includes three REGEX functions — REGEXTEST, REGEXEXTRACT, and REGEXREPLACE — that work just like any other worksheet formula. You can validate, extract, and clean text data using regular expressions directly in your cells, no coding required.
REGEX (regular expressions) is a syntax for matching text patterns. Excel's REGEX functions let you use this power inside worksheet formulas.
Availability:
The simplest of the three. REGEXTEST returns
Parameters:
Example 2 — Check for Phone Numbers:
Returns
REGEXEXTRACT pulls out the portion of text that matches your pattern. This is the function you will use most often, especially for text extraction tasks.
Syntax:
Parameters:
Example 2 — Extract Product Codes:
If cell A2 contains "Order PRD-3842 shipped", this returns
If cell A2 contains "Order 3842 contains 5 items", this returns
Returns each capture group separately: "John" in one column, "30" in the next.
REGEXREPLACE finds text that matches your pattern and replaces it with something else.
Syntax:
Parameters:
Removes all non-digit characters from a phone number. Converts "(555) 123-4567" to "5551234567".
Example 2 — Standardize Date Format:
Converts "3/14/2026" to "2026-3-14" (ISO format).
Example 3 — Replace First Occurrence Only:
Replaces only the first "old" in the text, leaving later occurrences unchanged.
Say you have a column of messy customer entries:
Step 1 — Validate the entry format:
Step 2 — Extract name:
Returns "J0hn_D0e".
Step 3 — Extract and clean phone:
Returns "5551234567".
Step 4 — Extract state:
Returns "NY".
All four formulas reference the same source cell and update automatically when your data changes.
Excel's native REGEX functions — REGEXTEST, REGEXEXTRACT, and REGEXREPLACE — turn complex text manipulation tasks into simple worksheet formulas. No VBA, no add-ins, no scripting.
REGEXEXTRACT is especially useful when cleaning data exported from other systems. Pulling out exactly what is needed with one formula eliminates a lot of manual editing.
Try it now: Open Excel, type a few sample strings, and test each REGEX function. The fastest way to learn is by experimenting with real text patterns.
What Are REGEX Functions in Excel?
- Excel 365 (Current Channel) — fully available
- Excel 2024 — fully available
- Excel for the Web — fully available
- Excel 2021 or earlier — not available (use VBA or Power Query instead)
REGEXTEST — Check If Text Matches a Pattern
TRUE if the text matches your pattern and FALSE if it doesn't.
Syntax:
=REGEXTEST(text, pattern, [case_sensitivity])text— the cell or string to checkpattern— your regex pattern (as text)case_sensitivity— optional.0(default, case-sensitive) or1(case-insensitive)
| A | B | Formula |
|---|---|---|
| user@example.com | TRUE | =REGEXTEST(A2, "^[\\w.-]+@[\\w.-]+\\.\\w{2,}$") |
| not-an-email | FALSE | =REGEXTEST(A3, "^[\\w.-]+@[\\w.-]+\\.\\w{2,}$") |
=REGEXTEST(A2, "\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}")TRUE if the cell contains a US phone number pattern like (555) 123-4567 or 555.123.4567.
Practical use: Combine REGEXTEST with conditional formatting to highlight rows with invalid data, or use it inside IF for data cleaning:
=IF(REGEXTEST(A2, "^[A-Z]{2}\\d{4}$"), "Valid code", "Invalid code")REGEXEXTRACT — Extract Text Matching a Pattern
=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])text— the cell or string to searchpattern— your regex patternreturn_mode— optional.0(default, first match),1(all matches as array),2(capture groups)case_sensitivity— optional.0(case-sensitive) or1(case-insensitive)
| A | B | Formula |
|---|---|---|
| john@company.com | company.com | =REGEXEXTRACT(A2, "@(.+)") |
=REGEXEXTRACT(A2, "PRD-\\d{4}")PRD-3842.
Example 3 — Extract All Matches (return_mode=1):
=REGEXEXTRACT(A2, "\\d+", 1){3842, 5} as a vertical array. You will need Excel's current-channel update for array return support.
Example 4 — Capture Groups (return_mode=2):
=REGEXEXTRACT("John: 30, Jane: 25", "(\\w+): (\\d+)", 2)REGEXREPLACE — Replace Text Matching a Pattern
=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])text— the cell or string to modifypattern— your regex patternreplacement— the new text (you can use$1,$2to reference capture groups)occurrence— optional.0(default, replace all occurrences) or a number to replace only the Nth matchcase_sensitivity— optional.0(case-sensitive) or1(case-insensitive)
=REGEXREPLACE(A2, "[^\\d]", "")=REGEXREPLACE(A2, "(\\d{1,2})/(\\d{1,2})/(\\d{4})", "$3-$1-$2")=REGEXREPLACE(A2, "old", "new", 1)Putting It All Together: Clean Customer Data
| Raw Data | Goal |
|---|---|
| J0hn_D0e: 555-123-4567 (NY) | Extract clean name, phone, state |
=REGEXTEST(A2, "^\\w+: \\d{3}-\\d{3}-\\d{4} \\([A-Z]{2}\\)$")=REGEXEXTRACT(A2, "^(\\w+)", 2)=REGEXREPLACE(REGEXEXTRACT(A2, "\\d{3}-\\d{3}-\\d{4}"), "-", "")=REGEXEXTRACT(A2, "\\(([A-Z]{2})\\)")Limitations and Tips
Performance
REGEX functions are slower than basic text functions (LEFT, MID, FIND) on large datasets. For 10,000+ rows, use them sparingly or combine with LET to calculate once and reuse — a pattern also used by other modern Excel functions for performance:=LET(
email, A2,
valid, REGEXTEST(email, "^[\\w.-]+@[\\w.-]+\\.\\w{2,}$"),
IF(valid, "OK", "Check")
)Regex Syntax Differences
Excel's REGEX engine follows the .NET regex syntax, which is similar to Perl but has some differences:- Use
\\dfor digits (double backslash inside Excel strings) - Use
\\wfor word characters - Use
$1,$2for capture group references (not\1,\2)
Combine with Other Functions
- LET — store your regex pattern once
- LAMBDA — create custom regex functions you can reuse
- TRIM — clean whitespace before regex processing
Conclusion
Article Topics
Recommended Next Reading
Excel
=EXCEL(...)Excel REGEXEXTRACT: Extract Patterns and Substrings
Explore ↗
Excel
=FILTER(...)Excel TEXTJOIN with Conditions: Merge Filtered Strings
Explore ↗
Excel
=EXCEL(...)Excel ROUND Function: MROUND, CEILING & FLOOR Guide
Explore ↗
Share this tutorial
Discussion & Community
Share questions, tips, or edge-cases about this spreadsheet formula.