Spreadsheet Practice

How to extract text between two characters in Excel

Excel formula

=TEXTBEFORE(TEXTAFTER(A2,$E$1),$G$1)

Take the text after the first character, then the text before the second: =TEXTBEFORE(TEXTAFTER(A2,"@"),".").

Result on the example
one result per row in B2, filled down to B6
Works in
Excel 2024 and Microsoft 365
Google Sheets
Different formula, see below

See it work

The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.

How it works

TEXTAFTER cuts off everything up to the @, leaving "northwind.example". TEXTBEFORE then keeps what comes before the next dot. Because the second search runs on what is left, the dot in "lena.park" never gets in the way.

The MID version does the same with positions: start one character after the @, and search for the dot starting from the @ (FIND's third argument).

=TEXTBEFORE(TEXTAFTER(A2,$E$1),$G$1)

Result"northwind"

  1. A2"lena.park@northwind.example"

    The value in A2.

  2. $E$1"@"

    The value in E1.

  3. TEXTAFTER(A2,$E$1)"northwind.example"

    TEXTAFTER: Text after a delimiter.

    • textA2"lena.park@northwind.example"
    • delimiter$E$1"@"
  4. $G$1"."

    The value in G1.

  5. TEXTBEFORE(TEXTAFTER(A2,$E$1),$G$1)"northwind"

    TEXTBEFORE: Text before a delimiter.

    • textTEXTAFTER(A2,$E$1)"northwind.example"
    • delimiter$G$1"."

In Google Sheets

Google Sheets needs a different formula: =MID(A2,FIND($E$1,A2)+1,FIND($G$1,A2,FIND($E$1,A2)+1)-FIND($E$1,A2)-1). On the same data it gives the same result. Here it is running in Google Sheets mode.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=MID(A2,FIND($E$1,A2)+1,FIND($G$1,A2,FIND($E$1,A2)+1)-FIND($E$1,A2)-1)northwind, contoso, fabrikam…Works in every version and in Google Sheets. The length is the end position minus the start position, minus one.

Common mistakes

  • Searching for the dot from the start of the text finds the one in "lena.park", before the @, and MID gets a negative length. Start the second FIND after the first character.
  • If either character is missing you get #N/A or #VALUE!. Wrap the formula in IFERROR(…,"").

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Extract text between two characters

In B2, extract the text between the character in E1 and the next character in G1, then fill down to B6.

Questions

How do I extract text between two words?

Use the words as delimiters: =TEXTBEFORE(TEXTAFTER(A2,"from ")," to").

How do I get the text between the second and third dash?

Give TEXTAFTER an instance number: =TEXTBEFORE(TEXTAFTER(A2,"-",2),"-").

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.