How-to recipes · Text
How to extract text between two characters in Excel
Pull out the text between brackets, dashes or other delimiters with TEXTBEFORE and TEXTAFTER in Microsoft 365, or MID and FIND in older Excel.
Product descriptions with the colour in brackets, order references wrapped in square brackets inside an email subject, invoice numbers whose middle part is the year, email addresses whose domain you want to group by. All of these are the same task: find a starting character, find an ending character, and return what lies between them. Microsoft 365 makes this almost readable English; older versions need MID and FIND, which are worth understanding because you will see them in many existing workbooks.
The example data
Four texts in A2:A5, each with a different kind of delimiter: round brackets, square brackets, the same character (dash) on both sides, and an email address.
Microsoft 365: TEXTAFTER then TEXTBEFORE
Take everything after the opening character, then everything before the closing character:
| A | B | C | |
|---|---|---|---|
| 1 | Text | ||
| 2 | Desk lamp (Black) 40W | Black | |
| 3 | Order ref [SO-2231] confirmed | ||
| 4 | INV-2026-0042 | ||
| 5 | maria.lopez@example.com |
TEXTAFTER returns "Black) 40W"; TEXTBEFORE cuts it at the closing bracket.
Result: Black
The same pattern works for any pair of delimiters: =TEXTBEFORE(TEXTAFTER(A3,"["),"]") returns SO-2231, and the email domain without the extension is =TEXTBEFORE(TEXTAFTER(A5,"@"),"."), which returns example.
When both delimiters are the same character
For INV-2026-0042 the text between the first and second dash is the year. Because TEXTAFTER cuts at the first dash, the remaining text 2026-0042 starts with the part you want, and TEXTBEFORE cuts at the next dash:
| A | B | C | |
|---|---|---|---|
| 1 | Text | ||
| 2 | Desk lamp (Black) 40W | ||
| 3 | Order ref [SO-2231] confirmed | ||
| 4 | INV-2026-0042 | 2026 | |
| 5 | maria.lopez@example.com |
TEXTAFTER returns 2026-0042, TEXTBEFORE returns 2026.
Result: 2026
Both functions take an instance number: TEXTAFTER(A4,"-",2) returns what follows the second dash (0042), and -1 counts from the end. If the delimiter is missing, they return #N/A; their if_not_found argument lets you return something else, for example =TEXTBEFORE(TEXTAFTER(A2,"(",,,,""),")",,,,"") returns an empty text when there are no brackets.
Excel 2016 and 2019: MID and FIND
MID needs a start position and a length. FIND supplies both: the start is one character after the opening bracket, and the length is the distance between the brackets minus one:
| A | B | C | |
|---|---|---|---|
| 1 | Text | ||
| 2 | Desk lamp (Black) 40W | Black | |
| 3 | Order ref [SO-2231] confirmed | ||
| 4 | INV-2026-0042 | ||
| 5 | maria.lopez@example.com |
FIND("(",A2) is 11 and FIND(")",A2) is 17, so MID starts at 12 and takes 5 characters.
Result: Black
FIND("(",A2)+1: the first character after the opening bracket.FIND(")",A2)-FIND("(",A2)-1: the number of characters between the brackets.MID(text, start, length)returns that slice.
For the same character on both sides, tell the second FIND where to start searching with its third argument, so it skips the first dash:
=MID(A4,FIND("-",A4)+1,FIND("-",A4,FIND("-",A4)+1)-FIND("-",A4)-1)It returns 2026. The inner FIND("-",A4)+1 is the position just after the first dash, where the search for the second dash begins.
Microsoft 365 with regular expressions
Current Microsoft 365 builds include REGEXEXTRACT, which describes the pattern in one expression: =REGEXEXTRACT(A2,"\((.*?)\)",2) returns the text inside the brackets. Regular expressions are powerful for messy data but harder to read; TEXTBEFORE/TEXTAFTER are enough for most delimiter jobs.
Pitfalls
- Missing delimiters give
#VALUE!(FIND) or#N/A(TEXTAFTER). Wrap the formula in IFERROR when some rows may not contain them. - Case. FIND is case-sensitive; use SEARCH if the delimiter is a word that may appear in different case, such as ref: or REF:.
- Nested or repeated brackets.
Lamp (Black (matt))breaks the simple logic. Decide which pair you need and use the instance arguments, or REGEXEXTRACT. - Numbers come out as text. Extracting 2026 gives the text "2026". Use
--or VALUE to turn it into a number:=--TEXTBEFORE(TEXTAFTER(A4,"-"),"-").
A worked plan for a whole column
When you clean a column of product descriptions, first check how many rows actually contain the delimiter, for example =COUNTIF(A2:A500,"*(*"). If every row has it, a plain formula is enough. If only some rows do, use the if_not_found argument or IFERROR so the other rows stay blank instead of showing errors, then filter the result column for blanks and look at those rows by hand. Finally copy the results and paste them as values before you delete or sort the source column.