Extract an email domain with REGEXEXTRACT
REGEXEXTRACT returns the part of a text cell that matches a regular expression. With the pattern "@(.+)$" it returns the domain of an email address.
=REGEXEXTRACT(B2,"@(.+)$")The sheet: Leads sheet: column A is Name, column B is Email. Column C should hold the company domain from each email, so leads can be grouped by company.
How it works, step by step
- 01B2 holds an email address such as maria.chen@northwind.io.
- 02The pattern "@(.+)$" looks for the @ sign, then captures one or more characters (.+) up to the end of the text ($).
- 03The parentheses form a capture group, so REGEXEXTRACT returns only the captured part, northwind.io, without the @.
- 04Fill the formula down column C to get a domain for every lead.
The same logic in four tools
=TEXTAFTER(B2,"@")=REGEXEXTRACT(B2,"@(.+)$")SELECT email,
substring(email from '@(.+)$') AS domain
FROM leads;import pandas as pd
leads["domain"] = leads["email"].str.extract(r"@(.+)$", expand=False)Mistakes that break it
- !REGEXEXTRACT returns #N/A when there is no match, for example a blank cell or an address missing its @. Wrap it in IFERROR(...,"") to leave those rows empty.
- !Stray spaces and mixed case carry through to the domain. TRIM the email first and LOWER the result so Northwind.io and northwind.io group together.
- !REGEXEXTRACT only accepts text. A number in the cell returns an error, so wrap the cell in TO_TEXT if the column mixes types.
- !The Excel formula uses TEXTAFTER, which needs Microsoft 365 or Excel 2024. Older Excel can use =MID(B2,FIND("@",B2)+1,LEN(B2)).
Common questions
- How do I extract the domain from an email in Excel?
- In Microsoft 365, use =TEXTAFTER(B2,"@"). In older versions, use =MID(B2,FIND("@",B2)+1,LEN(B2)), which returns everything after the @.
- What does the $ mean in a REGEXEXTRACT pattern?
- $ anchors the match to the end of the text. In "@(.+)$" it makes the captured part run from just after the @ to the last character.
- How do I extract text with regex in pandas?
- Use Series.str.extract with a raw string pattern that has one capture group, for example df["email"].str.extract(r"@(.+)$", expand=False). Rows without a match return NaN.
Got a version of this with your own ranges?
Paste it into the free translator and get the same breakdown for your exact formula. To run it against a real file, upload the CSV and describe the formula you need in a sentence.