How to Use REGEXEXTRACT in Excel (Examples and Fixes)

Use REGEXEXTRACT in Excel to pull out text that follows a recognizable pattern, even when it moves around inside a cell. For example, =REGEXEXTRACT(A11,"[A-Z]{2}-[0-9]{4}",1) extracts every code made of two uppercase letters, a hyphen, and four digits from A11.

This is useful for cleaning notes that mix ordinary sentences with ticket numbers or product codes. Start with a pattern you can explain, then test it against records that should and should not match.

Version requirement: Microsoft’s REGEXEXTRACT documentation lists Excel for Microsoft 365 and Microsoft 365 for Mac. The ticket example below was checked in Excel for Windows. Do not assume the function is included in Excel 2021 or Excel 2024.

Extract two ticket codes from one cell

  1. Enter this sample text in A11: Ticket AB-1042; replacement CD-2087.
  2. Select A12. Leave B12 empty because the formula will return two matches.
  3. Enter =REGEXEXTRACT(A11,"[A-Z]{2}-[0-9]{4}",1) and press Enter.
  4. Check the output. A12 should contain AB-1042 and B12 should contain CD-2087.
Excel shows the sample ticket sentence in A11 and the extracted codes AB-1042 and CD-2087 across row 12.
Both codes are extracted from the same cell. The source sentence remains intact.

Read the pattern in three pieces: [A-Z]{2} asks for two uppercase letters, - matches a literal hyphen, and [0-9]{4} asks for four digits. The final 1 tells Excel to return all matches.

That pattern describes a format; it does not prove a ticket exists. It can also find the code inside a longer string. If codes must stand alone, use word boundaries:

=REGEXEXTRACT(A11,"\b[A-Z]{2}-[0-9]{4}\b",1)

For this example, a five-digit code such as AB-10427 should fail the stricter pattern instead of producing a shortened ticket number. Decide whether underscores, punctuation, or adjacent letters are allowed in your real data before choosing boundaries.

Choose first match, all matches, or captured parts

The argument order is REGEXEXTRACT(text,pattern,[return_mode],[case_sensitivity]). The last two arguments are optional.

Mode Purpose Example using A11
0, or omitted First complete match =REGEXEXTRACT(A11,"[A-Z]{2}-[0-9]{4}") returns AB-1042.
1 Every complete match =REGEXEXTRACT(A11,"[A-Z]{2}-[0-9]{4}",1) returns both codes.
2 Captured parts of the first match =REGEXEXTRACT(A11,"([A-Z]{2})-([0-9]{4})",2) returns AB and 1042.

Parentheses define the parts to capture. Mode 2 uses the first matching code; it does not automatically make a table containing the letter and number parts of every code in the sentence.

If you need all matches in one cell, join them:

=TEXTJOIN(", ",TRUE,REGEXEXTRACT(A11,"\b[A-Z]{2}-[0-9]{4}\b",1))

The result for the sample is AB-1042, CD-2087. This layout is useful when you are filling a formula down beside many notes and want one output cell per note.

Handle lowercase codes and missing matches

Matching is case-sensitive by default. To accept ab-1042 as well as AB-1042, set the fourth argument to 1:

=REGEXEXTRACT(A11,"\b[A-Z]{2}-[0-9]{4}\b",1,1)

This changes which text qualifies. It does not convert the extracted letters to uppercase.

When a note contains no matching code, use IFNA to display an explicit review label:

=IFNA(REGEXEXTRACT(A11,"\b[A-Z]{2}-[0-9]{4}\b"),"No ticket code")

A visible label is easier to audit than a silent blank. IFNA also leaves unrelated errors visible, so an invalid pattern or blocked output is less likely to be mistaken for a note without a ticket number.

Adapt the pattern to the information you need

Use these as small tests, not universal validators. Put the sample text in A11 and enter one formula at a time in an empty area.

Sample text Formula Expected result
Batch 0048 ready =REGEXEXTRACT(A11,"[0-9]+") 0048, as text
Adapter [USB-C] packed =REGEXEXTRACT(A11,"\[([^\]]+)\]",2) USB-C
Review 2026-09-16 =REGEXEXTRACT(A11,"[0-9]{4}-[0-9]{2}-[0-9]{2}") 2026-09-16, as text

[0-9]+ matches consecutive digits. It does not include a minus sign or decimal separator. In the bracket example, the escaped brackets identify literal [ and ] characters, while the parentheses capture the text between them.

The date pattern checks the shape of a date. It would also match a date-shaped value with an invalid month. Validate calendar dates separately before using them for calculations.

Extracted values are text. Keep that behavior for identifiers with leading zeros. Only use VALUE(...) when the extracted result represents a number you actually want to calculate with; converting 0048 to a number loses the leading zeros.

More everyday patterns

Pull out an email address

For a cell such as Contact [email protected] before Friday, this formula returns [email protected]:

=REGEXEXTRACT(A11,"[\w.+-]+@[\w-]+\.[\w.]+")

\w matches a letter, digit, or underscore. The pattern is good enough for cleaning a contact list, but it does not check that an address is real.

Get a number you can calculate with

REGEXEXTRACT always returns text, so totals and averages will ignore the result. Wrap it in VALUE to turn it into a number. For Total due: 42.50 USD:

=VALUE(REGEXEXTRACT(A11,"[0-9]+(\.[0-9]+)?"))

The result is the number 42.5, which you can format as currency. The part in parentheses makes the decimals optional, so 42 on its own also works.

Run it down a whole column

With the default first-match mode, you can give REGEXEXTRACT a range instead of one cell, such as =REGEXEXTRACT(A2:A20,"[A-Z]{2}-[0-9]{4}"). It spills one result per row, so you don’t need to fill the formula down. Rows without a match show #N/A, which IFNA can replace with a label.

Use REGEXTEST and REGEXREPLACE with it

Excel has two related functions that use the same patterns:

  • REGEXTEST returns TRUE or FALSE. =REGEXTEST(A11,"[A-Z]{2}-[0-9]{4}") tells you whether a note contains a ticket code, which is useful in a filter or an IF formula.
  • REGEXREPLACE swaps matching text for something else. =REGEXREPLACE(A11,"[0-9]{4}","####") hides every group of four digits, for example before you share a sheet.

Test a pattern with REGEXTEST first. If it returns TRUE on the rows you expect and FALSE on the others, it is ready for REGEXEXTRACT.

Troubleshoot the formula before filling it down

  • #NAME? or _xlfn.REGEXEXTRACT: Check the function name and your Excel version. If unavailable, use an older text-function method or a supported Microsoft 365 installation.
  • #N/A: Test whether the input really matches the pattern, including case, spaces, hyphen type, and digit count.
  • #SPILL!: Clear or move cells that block the multiple-match result. Keep spilling formulas outside Excel Tables.
  • An invalid-pattern error: Check paired parentheses and brackets. Copy straight quotation marks into Excel, not typographic quotes.
  • The wrong digits appear: A general pattern such as [0-9]+ may find a quantity before it reaches the ticket number. Include the code’s letters or surrounding label.

Before applying the formula to hundreds of records, try a valid code, a lowercase code, two codes, no code, a code with leading zeros, and a nearly valid code with an extra digit. Those cases reveal whether the pattern matches your actual requirement.

For text at a known position, LEFT, RIGHT, and MID may be easier to maintain. If your task is only to extract text between two delimiters, you may not need regex. Choose REGEXEXTRACT when the recognizable format of the text is what identifies it.

Frequently asked questions

Is REGEXEXTRACT the same as in Google Sheets?

The idea is the same, but the details differ. Google Sheets has had REGEXEXTRACT for years, with only two arguments. It returns the first match, or the captured groups if the pattern has them. Excel adds return_mode and case_sensitivity, so a formula copied from Sheets may need adjusting.

What pattern rules does Excel use?

Excel’s REGEX functions use the PCRE2 flavor of regular expressions. Most common tutorials and online regex testers support this style, so patterns you find there usually work.

Can I extract text without regular expressions?

Yes, for simple cases. TEXTBEFORE and TEXTAFTER pull out text around a fixed character, such as everything after the @ in an email address. Use REGEXEXTRACT when the text you want follows a pattern rather than a fixed marker.

Related: separate numbers in a cell in Excel.

Related: how to use the SEARCH function in Excel.

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy