ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. Excel REGEX Functions: REGEXTEST, REGEXEXTRACT, REGEXREPLACE

Excel REGEX Functions: REGEXTEST, REGEXEXTRACT, REGEXREPLACE

By ExcelReady Team·Updated November 3, 2026·6 min read

The short answer

Excel has three regex functions in Microsoft 365: REGEXTEST checks whether text matches a pattern and returns TRUE or FALSE, REGEXEXTRACT pulls out the matching text, and REGEXREPLACE swaps it for something else. For example, =REGEXEXTRACT(A2,"\d+") returns the first number in A2. Older versions show #NAME? and need FIND, SEARCH or SUBSTITUTE.

Key takeaways

  • REGEXTEST(text, pattern) returns TRUE or FALSE. REGEXEXTRACT returns the match. REGEXREPLACE replaces it.
  • \d means a digit, \s a space, \w a letter, digit or underscore, and + means one or more.
  • Matching is case-sensitive by default. Set the case_sensitivity argument to 1 to ignore case.
  • REGEXEXTRACT returns text. Wrap it in VALUE or -- if you need a number.
  • If you see #NAME?, your Excel doesn't have them yet. Use FIND, SEARCH, MID and SUBSTITUTE instead.
On this page+
  1. What are the REGEX functions in Excel?
  2. Regex pattern basics
  3. REGEXTEST: check if text matches a pattern
  4. REGEXEXTRACT: pull text out of a cell
  5. REGEXREPLACE: clean and reformat text
  6. No REGEX functions? Use FIND, SEARCH and SUBSTITUTE
  7. Common REGEX errors and fixes
  8. Practise it

Regex in Excel means three functions: REGEXTEST, REGEXEXTRACT and REGEXREPLACE. A regular expression (regex) is a short pattern that describes text, such as "four digits" or "anything before the @". With these functions you can check, extract and clean text that would need long FIND and MID formulas before. This guide explains the syntax, the pattern symbols you'll use most, and what to do if your Excel doesn't have them.

What are the REGEX functions in Excel?#

Excel's regex functions each take a piece of text and a pattern. They differ in what they give back.

FunctionSyntaxReturns
REGEXTEST=REGEXTEST(text, pattern, [case_sensitivity])TRUE if the pattern is found, otherwise FALSE
REGEXEXTRACT=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])The matching text
REGEXREPLACE=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])The text with matches replaced

Version note: Microsoft added these functions to Microsoft 365 in 2024, first for Insiders and then for everyone on current builds. They work in Excel for Microsoft 365 on Windows and Mac, and in Excel for the web. Excel 2019 and Excel 2021 don't have them. If you use Excel 2024 or another one-time-purchase version, type =REGEXTEST( in a cell to check: if Excel doesn't suggest it, or the formula shows #NAME?, your version doesn't support it.

The patterns follow a common regex style called PCRE2, so most patterns you find in regex tutorials work here too.

Regex pattern basics#

A pattern mixes plain characters, which match themselves, with special symbols. You only need a handful to start:

SymbolMeansExample patternMatches
\dAny digit 0–9\d\d42
\DAny character that is not a digit\Dthe dash in 555-0142
\wA letter, digit or underscore\w+Anna
\sA space, tab or line break\s+one or more spaces
.Any single characterA.CABC, A-C
+One or more of the previous item\d+7, 4821
*Zero or more of the previous itemab*a, ab, abbb
{n}Exactly n of the previous item\d{4}2024
[ ]Any one character in the set[A-Z]any capital letter
^ and $Start and end of the text^INVtext starting with INV
( )A capture group(\d+)-(\d+)555-0142, as two parts
\.A real full stop\.com.com

Patterns go in double quotes like any text in a formula. If a pattern needs a double quote, type it twice: "".

REGEXTEST: check if text matches a pattern#

REGEXTEST returns TRUE when the pattern appears in the text. Use it to check codes, IDs and formats. Say A2 holds INV-2024-0583:

Excel formula
=REGEXTEST(A2,"^INV-\d{4}-\d{4}$")

The result is TRUE. The pattern means: start of the text, INV-, four digits, a dash, four digits, end of the text. INV-24-583 would return FALSE. Without ^ and $, the pattern could match inside longer text.

Matching is case-sensitive by default, so inv-2024-0583 fails too. Add 1 as the third argument to ignore case: =REGEXTEST(A2,"^inv-\d{4}-\d{4}$",1). Combine REGEXTEST with IF or FILTER to flag or list the rows that pass.

REGEXEXTRACT: pull text out of a cell#

REGEXEXTRACT returns the part of the text that matches. If A3 holds Order 4821, 3 items:

FormulaResult
=REGEXEXTRACT(A3,"\d+")4821 (the first match)
=REGEXEXTRACT(A3,"\d+",1)4821 and 3, spilled into two cells
=VALUE(REGEXEXTRACT(A3,"\d+"))4821 as a real number

The third argument, return_mode, picks what comes back: 0 (the default) is the first match, 1 is every match, and 2 is the capture groups of the first match. For a date written as 2024-11-03, =REGEXEXTRACT(A4,"(\d{4})-(\d{2})-(\d{2})",2) returns 2024, 11 and 03 in separate cells.

The result is always text, so a number on the left of the cell won't add up. Wrap it in VALUE or put -- in front. For the non-regex ways to do this, see how to extract numbers from text in Excel.

A practical example: to pull an email address out of a sentence like Contact: anna.lee@example.com, use =REGEXEXTRACT(A5,"[\w.+-]+@[\w-]+\.[\w.]+"). It returns anna.lee@example.com. Real email rules are more complex, so treat this as a quick extractor, not a full validator.

REGEXREPLACE: clean and reformat text#

REGEXREPLACE finds every match and replaces it. It is the regex version of SUBSTITUTE, and it can replace patterns, not just fixed text.

Text in A2FormulaResult
Call 555-0142 now=REGEXREPLACE(A2,"\D","")5550142
Lee, Anna=REGEXREPLACE(A2,"\s+"," ")Lee, Anna
Lee, Anna=REGEXREPLACE(A2,"(\w+), (\w+)","$2 $1")Anna Lee

The first formula deletes every non-digit. The second turns any run of spaces into one space. The third uses capture groups: $1 is the first group in brackets and $2 is the second, so the name is flipped.

The optional occurrence argument chooses which match to replace. Leave it out, or use 0, to replace all of them. Use 1 for the first match only.

No REGEX functions? Use FIND, SEARCH and SUBSTITUTE#

Every version of Excel can do the common regex jobs with older text functions. The formulas are longer, but they are what most job tests expect.

TaskRegex formulaFormula for any version
Number after a #=REGEXEXTRACT(A2,"\d+")=MID(A2,SEARCH("#",A2)+1,4)
Remove dashes=REGEXREPLACE(A2,"-","")=SUBSTITUTE(A2,"-","")
Starts with INV=REGEXTEST(A2,"^INV")=LEFT(A2,3)="INV"
Contains "late"=REGEXTEST(A2,"late",1)=ISNUMBER(SEARCH("late",A2))

SEARCH finds the position of text and ignores case, while FIND is case-sensitive. The SEARCH function guide and the article on FIND vs SEARCH for locating text show how to combine them with MID. SUBSTITUTE swaps fixed text: see the SUBSTITUTE function guide and SUBSTITUTE vs REPLACE. To strip unwanted characters, read how to remove characters in Excel.

For counting and summing, wildcards are a mini pattern language that works everywhere: =COUNTIF(A2:A20,"INV-*") counts IDs starting with INV-. The guide to wildcards in COUNTIF and SUMIF covers *, ? and ~.

Common REGEX errors and fixes#

Most problems come from the version, the pattern or the result type.

  • #NAME? means your Excel doesn't have the function. Use the older formulas above.
  • An error when nothing matches. REGEXEXTRACT can't return a match that isn't there. Wrap it in IFERROR: =IFERROR(REGEXEXTRACT(A2,"\d+"),"").
  • FALSE when you expect TRUE. Check capital letters, since matching is case-sensitive by default, and check that ^ and $ aren't too strict.
  • Numbers that won't add up. The result is text. Wrap it in VALUE.
  • A full stop that matches everything. . means any character. Write \. for a real full stop.

Practise it#

Regex is powerful, but the building blocks are the classic text skills that job tests check. Practise FIND and SEARCH in a live spreadsheet: you'll pull order numbers out of text, just like the exercise here. Then practise cleaning messy text with TRIM and SUBSTITUTE. Each formula is checked as soon as you press Enter.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Without regex, pull the 4-digit order number out of A2. In B2, use SEARCH to find the # sign, then MID to return the 4 characters after it.

fx
ABCD
1
Message
Order number
2
Order #4821 shipped
3
Order #5310 delayed
4
Order #6045 shipped
5
Order #7182 on hold
6
Order #8237 shipped
7
8
9

Tip: SEARCH("#",A2) gives the position of #. The number starts one character later, and it is 4 characters long.

Practise this in a lesson

LessonFIND and SEARCHLocate a character or word inside text with FIND or SEARCH, then use that position to split names and pull out order numbers.LessonCleaning messy textFix stray spaces, random capitals and inconsistent separators in imported data with TRIM, PROPER, UPPER, LOWER and SUBSTITUTE.Function guideSEARCHLocate text regardless of capitals with Excel's SEARCH, use wildcards, and build "contains" checks with ISNUMBER. Examples and live practice.Function guideSUBSTITUTESwap or strip characters with Excel's SUBSTITUTE: clean phone numbers, change one occurrence and count characters with LEN. Practice it live.

Frequently asked questions

Does Excel support regex?

+

Yes, in Microsoft 365. Microsoft added REGEXTEST, REGEXEXTRACT and REGEXREPLACE in 2024. Older versions such as Excel 2019 and 2021 don't have them and show #NAME?.

How do I extract numbers from text with regex in Excel?

+

Use =REGEXEXTRACT(A2,"\d+") for the first number, or =REGEXEXTRACT(A2,"\d+",1) to return every number as a spilled list. The result is text, so wrap it in VALUE to calculate with it.

Is REGEXTEST case-sensitive?

+

Yes, by default. Add 1 as the third argument to ignore case, for example =REGEXTEST(A2,"^inv",1), which matches INV, Inv and inv.

What can I use instead of regex in older Excel?

+

Use SEARCH or FIND to locate text, MID, LEFT and RIGHT to pull it out, SUBSTITUTE to replace it, and wildcards like * and ? in COUNTIF. They need longer formulas but work in every version.

Sources

  • SEARCH, SEARCHB functions - Microsoft Support
  • SUBSTITUTE function - Microsoft Support
  • MID, MIDB functions - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What are the REGEX functions in Excel?
  2. Regex pattern basics
  3. REGEXTEST: check if text matches a pattern
  4. REGEXEXTRACT: pull text out of a cell
  5. REGEXREPLACE: clean and reformat text
  6. No REGEX functions? Use FIND, SEARCH and SUBSTITUTE
  7. Common REGEX errors and fixes
  8. Practise it

Keep reading

Text· 6 min read

Extract Numbers From Text in Excel

To extract a number from text in Excel, cut it out with a text function and convert it with VALUE. For a number after a dash, use =VALUE(RIGHT(A2,LEN(A2)-FIND("-",A2))), or =VALUE(TEXTAFTER(A2,"-")) in Microsoft 365. Use LEFT for numbers at the start and MID for numbers in the middle. VALUE turns the result into a real number.

Text· 8 min read

SUBSTITUTE and REPLACE in Excel

Use SUBSTITUTE when you know the text you want to change: =SUBSTITUTE(A2,".","-") swaps every dot for a dash. Use REPLACE when you know the position: =REPLACE(A2,1,3,"XXX") overwrites the first three characters. SUBSTITUTE is case-sensitive and can change just one occurrence; REPLACE ignores what the characters say.

Text· 7 min read

Find the Position of Text in a Cell (FIND and SEARCH)

FIND and SEARCH return the position of some text inside a cell, as a number. =FIND(" ",A2) gives 5 for Dana Whitfield, because the space is the 5th character. FIND is case-sensitive; SEARCH ignores capitals and allows wildcards. Both return #VALUE! when the text isn't there, so wrap them in ISNUMBER to test whether a cell contains a word.

More on text

  • How to Remove Characters From Text in Excel
  • Remove Duplicates Within a Cell in Excel
  • Remove the First or Last Characters in Excel
  • Remove Line Breaks From Cells in Excel
  • How to Remove Numbers From Text in Excel
  • How to Remove Spaces in Excel (Extra, Leading, All)
All text articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free