Excel guide · 4 min read
How to extract text between two characters in Excel
=TEXTBEFORE(TEXTAFTER(A2,"("),")") returns the text between the first ( and the next ). TEXTAFTER cuts off everything up to the opening character, and TEXTBEFORE cuts off everything from the closing one. In older versions use =MID(A2,FIND("(",A2)+1,FIND(")",A2,FIND("(",A2))-FIND("(",A2)-1).Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | |
|---|---|---|
| 1 | Contact | Shipment note |
| 2 | Dana Kim (Finance) <[email protected]> | Pallet 14 from Leeds to Madrid, 2 days |
| 3 | Luis Ortega (Sales) <[email protected]> | Pallet 9 FROM Porto TO Lyon, 3 days |
| 4 | Priya Shah <[email protected]> | Pallet 22 from Gdansk to Oslo, 4 days |
| 5 | Tom Reyes (Ops) (contractor) <[email protected]> | Pallet 3 from Rotterdam to Antwerp, 1 day |
| 6 | Ana Ruiz (R&D (EU)) <[email protected]> | Pallet 31 from Hamburg to Milan, 3 days |
| 7 | ||
| 8 | 1) Dana Kim (Finance) |
Download this sheet as an Excel practice file (.xlsx)
Method 1: TEXTBEFORE inside TEXTAFTER (Excel 365 and 2024)
The sheet is a contact export where each cell holds a name, a department in parentheses and an email in angle brackets. Read the formula from the inside out. TEXTAFTER(A2,"(") returns "Finance) <[email protected]>". TEXTBEFORE then keeps everything before the first ")" in that shorter text.
Because TEXTBEFORE only looks at what is left after the opening character, a ")" earlier in the cell can never confuse it. The same pattern works for any pair: swap in "[" and "]", "{" and "}", or two different characters.
Result: Finance
Finance. Fill it down and A3 gives Sales.
Two different characters: an email between < and >
The delimiters do not have to match. To pull the address out of "Name <email>", cut after "<" and before ">". This is the usual way to clean the "From" column of an email export.
Result: [email protected]
Between two words, ignoring case
Delimiters can be words. Column B holds shipment notes, and the origin city sits between "from " and " to ". Put the spaces inside the delimiters so the result has no spaces at either end. Leave them out and you get " Leeds" with a leading space, which breaks lookups.
TEXTBEFORE and TEXTAFTER are case-sensitive by default, so on row 3 (FROM Porto TO Lyon) the basic version returns #N/A. Their fourth argument, match_mode, set to 1 makes the match ignore case.
Keep the spaces in " to " for another reason too: "Porto" contains "to". With "to" alone, row 3 returns "Por".
Result: Porto
Porto. Without the two 1s it returns #N/A, because "from" does not match "FROM".
Method 2: MID and FIND (every version)
MID(text, start, length) needs a start position and a length. The start is one character after the "(", and the length is the distance from there to the ")".
Give the second FIND a start position, FIND(")",A2,FIND("(",A2)), so it looks for the closing character only after the opening one. Without it, a ")" earlier in the cell breaks the formula. Row 8 holds "1) Dana Kim (Finance)": the short version finds the ")" after the 1, gets a negative length and returns #VALUE!. With the start argument it returns Finance.
FIND is case-sensitive. For word delimiters in older Excel, use SEARCH instead, which ignores case.
Result: Finance
Finance, even though the cell starts with "1)".
When a cell has no brackets
Priya Shah on row 4 has no department. TEXTAFTER returns #N/A when it cannot find the delimiter, and the MID and FIND version returns #VALUE!. Wrap the formula in IFERROR and choose what to show: "" for blank, or a label you can filter on.
TEXTAFTER and TEXTBEFORE also have their own if_not_found argument (the sixth), but in a nested formula you would need it on both functions. One IFERROR around the outside is simpler. Keep in mind that IFERROR hides every error, so test the formula on a few normal rows first.
Result: (none)
(none) for the row with no parentheses.
The second pair, nested brackets, or keeping the brackets
Second pair: Tom's cell has two groups, "(Ops) (contractor)". The third argument of TEXTAFTER is instance_num, so TEXTAFTER(A5,"(",2) starts after the second "(", and the formula returns contractor. In older Excel, find the second "(" with the SUBSTITUTE trick in the find nth occurrence guide.
Nested brackets: Ana's department is "(R&D (EU))". Stopping at the first ")" gives "R&D (EU". An instance_num of -1 searches from the end, so TEXTBEFORE(TEXTAFTER(A6,"("),")",-1) returns R&D (EU). Only use -1 when the cell has one outer group, because on Tom's row it returns "Ops) (contractor".
Keep the brackets: start MID at the "(" itself and add 1 to the length instead of subtracting it. The formula below returns (Finance).
Result: (Finance)
(Finance), with both parentheses.
No formulas: Flash Fill
For a one-off clean-up, Flash Fill copies a pattern from an example. It does not update when the source changes, and on mixed data like rows 4 to 6 check every result.
- In the column next to the data, type the result for the first row, for example Finance.
- Click the cell below and press Ctrl+E, or choose Data > Flash Fill.
- Scan the results, especially rows with no brackets or with two pairs.
Common mistakes
Result has a stray space at the start or end
Include the spaces in word delimiters ("from " and " to "), or wrap the result in TRIM.
#N/A on some rows only
Either the delimiter is missing or its case differs. Set match_mode to 1 for case, and wrap in IFERROR for rows without the delimiter.
#VALUE! from MID and FIND
The closing character appears before the opening one. Give the second FIND a start position: FIND(")",A2,FIND("(",A2)).
A short word delimiter matches inside another word
"to" matches the end of "Porto". Use " to " with spaces, or a longer, more specific delimiter.
FAQ
How do I extract text between parentheses in Excel?
Use =TEXTBEFORE(TEXTAFTER(A2,"("),")") in Excel 365 or 2024. In older versions use =MID(A2,FIND("(",A2)+1,FIND(")",A2,FIND("(",A2))-FIND("(",A2)-1).
How do I extract text between two different words?
Use the words as delimiters, with spaces included: =TEXTBEFORE(TEXTAFTER(A2,"from ",,1)," to ",,1). The 1 makes both matches ignore case.
How do I get text between the second set of brackets?
Give TEXTAFTER an instance number: =TEXTBEFORE(TEXTAFTER(A2,"(",2),")"). Use 3 for the third pair, and -1 for the last opening bracket.
How do I extract text between two identical characters, like two dashes?
=TEXTBEFORE(TEXTAFTER(A2,"-"),"-") returns the text between the first and second dash. For older Excel, see the find nth occurrence guide, which uses SUBSTITUTE to locate the second dash.
Is there a formula for text between characters in Excel 2016 or 2019?
Yes, MID with FIND. TEXTBEFORE and TEXTAFTER are only in Excel 365, Excel 2024 and Excel for the web, and older versions show #NAME? for them.
Functions used
TEXTBEFOREText before a delimiterTEXTAFTERText after a delimiterMIDCharacters from the middleFINDPosition of text (case-sensitive)SEARCHPosition of textIFERRORFallback when a formula errorsTRIMRemoves extra spaces
Related guides
- How to extract text after a character in Excel
- How to extract text before a character in Excel
- How to find the nth occurrence of a character in Excel
- How to extract the domain from an email address in Excel
- How to extract the first, last or nth word in Excel
- How to switch "Last, First" to "First Last" in Excel
Updated