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
- Enter this sample text in A11:
Ticket AB-1042; replacement CD-2087. - Select A12. Leave B12 empty because the formula will return two matches.
- Enter
=REGEXEXTRACT(A11,"[A-Z]{2}-[0-9]{4}",1)and press Enter. - Check the output. A12 should contain
AB-1042and B12 should containCD-2087.
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.
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.

Matt Jacobs has been working as an IT consultant for small businesses since receiving his Master’s degree in 2003. While he still does some consulting work, his primary focus now is on creating technology support content for SupportYourTech.com.
His work can be found on many websites and focuses on topics such as Microsoft Office, Apple devices, Android devices, Photoshop, and more.