Text formula page

Extract Domain From URL Formula

Use this for campaign reports, link exports, or content calendars that need URLs grouped by domain.

Best for

Extract domain names from URLs in spreadsheets.

What it returns

If A2 is https://www.example.com/pricing, the result is example.com.

Copy formulas

Excel formula
=TEXTBEFORE(TEXTAFTER(SUBSTITUTE(A2&"/","www.",""),"//"),"/")
Google Sheets formula
=REGEXEXTRACT(A2, "^(?:https?:\/\/)?(?:www\.)?([^\/\?#]+)")
Excel / Google Sheets difference

The Google Sheets regex handles optional protocols. The Excel formula expects URLs with a protocol such as https://.

Example data

Raw TextExample Result
Maya ChenMaya
SKU-1001-EastSKU
https://www.example.com/pricingexample.com
Acme North Acme North

Formula explanation

  • The formula removes www when present.
  • It extracts the host before the next slash, question mark, or hash.
  • Use IFERROR if some cells are not URLs.

What this formula does

Extract Domain From URL Formula is built around TEXTBEFORE. The example formula on this page is =TEXTBEFORE(TEXTAFTER(SUBSTITUTE(A2&"/","www.",""),"//"),"/"), and it is written against sample columns such as Raw Text, Example Result.

Excel and Google Sheets need different syntax for this task, so copy the version that matches the spreadsheet app you are using.

Text formulas are sensitive to spaces, delimiters, punctuation, and hidden line breaks. Clean the source text first when imported data contains inconsistent separators or nonbreaking spaces.

Use this pattern for this task: Extract domain names from URLs in spreadsheets. Review a few edge cases before filling the formula down across a large import.

Syntax pieceRole in the formula
Part 1The formula removes www when present.
Part 2It extracts the host before the next slash, question mark, or hash.
Part 3Use IFERROR if some cells are not URLs.

Practical use cases

Excel copy output
=TEXTBEFORE(TEXTAFTER(SUBSTITUTE(A2&"/","www.",""),"//"),"/")

Excel: Use this on imported CRM, CSV, or content rows where one text cell needs to be cleaned or split before analysis. Returns: If A2 is https://www.example.com/pricing, the result is example.com.

Google Sheets copy output
=REGEXEXTRACT(A2, "^(?:https?:\/\/)?(?:www\.)?([^\/\?#]+)")

Google Sheets: Use this before lookup, filtering, or duplicate checks so the text key is consistent across rows. Returns: If A2 is https://www.example.com/pricing, the result is example.com.

Common errors

  • Hidden spaces and line breaks can make text formulas look wrong even when the syntax is valid.
  • Modern Excel text functions such as TEXTSPLIT, TEXTBEFORE, and TEXTAFTER require newer Excel versions.
  • Formula separators can vary by locale in some spreadsheet settings.

Common errors and troubleshooting

IssueLikely causeFix
Copied formula gives an unexpected resultHidden spaces and line breaks can make text formulas look wrong even when the syntax is valid.Normalize spacing first, confirm the delimiter or pattern exists, and wrap the formula in IFERROR only after the pattern is correct.
Common setup problemModern Excel text functions such as TEXTSPLIT, TEXTBEFORE, and TEXTAFTER require newer Excel versions.Normalize spacing first, confirm the delimiter or pattern exists, and wrap the formula in IFERROR only after the pattern is correct.
Common setup problemFormula separators can vary by locale in some spreadsheet settings.Normalize spacing first, confirm the delimiter or pattern exists, and wrap the formula in IFERROR only after the pattern is correct.
Formula returns #VALUE! or no matchThe delimiter, word boundary, or pattern expected by the formula is not present in that row.Inspect a failed cell, confirm the delimiter exists, and add IFERROR only after the extraction rule is correct.
Output still contains strange spacesThe source text contains nonbreaking spaces, tabs, or line breaks that TRIM alone does not remove.Use CLEAN or SUBSTITUTE for those characters before applying the final extraction or cleanup formula.

When not to use this formula

  • Do not use simple text formulas for complex CSV parsing with quoted commas.
  • Do not use text extraction formulas when the source data should be cleaned once in a dedicated import step.

Alternatives

AlternativeWhen to use it
CSV Column CleanerUse when header names need cleanup before import.
REGEXEXTRACT Formula BuilderUse for repeatable Google Sheets pattern extraction.
FILTER Formula BuilderUse after text cleanup when you need matching rows.

Compare with related formulas

Formula or toolHow it differsUse it instead when
CSV Column CleanerCSV Column Cleaner solves a nearby workflow, while Extract Domain From URL Formula is focused on extract domain names from urls in spreadsheets.Use when header names need cleanup before import.
REGEXEXTRACT Formula BuilderREGEXEXTRACT Formula Builder solves a nearby workflow, while Extract Domain From URL Formula is focused on extract domain names from urls in spreadsheets.Use for repeatable Google Sheets pattern extraction.
FILTER Formula BuilderFILTER Formula Builder solves a nearby workflow, while Extract Domain From URL Formula is focused on extract domain names from urls in spreadsheets.Use after text cleanup when you need matching rows.

Test cases

TestPlatformFormulaReturns
Excel copy outputExcel=TEXTBEFORE(TEXTAFTER(SUBSTITUTE(A2&"/","www.",""),"//"),"/")If A2 is https://www.example.com/pricing, the result is example.com.
Google Sheets copy outputGoogle Sheets=REGEXEXTRACT(A2, "^(?:https?:\/\/)?(?:www\.)?([^\/\?#]+)")If A2 is https://www.example.com/pricing, the result is example.com.

Related formulas

FAQ

What does the Extract Domain From URL Formula do?

It supports this task: Extract domain names from URLs in spreadsheets. The example uses A2, but you should replace the ranges and criteria with the cells in your own workbook.

Does the Extract Domain From URL Formula work in Excel and Google Sheets?

Not exactly. This page shows a separate Google Sheets formula when the syntax differs.

What should I change before copying the formula?

Change the source ranges, criteria cells, and output range references so they match your sheet. Keep related ranges on the same rows unless the formula notes say otherwise.

Why does this text formula fail on some rows?

Those rows may not contain the delimiter, word boundary, or pattern the formula expects. Inspect failed examples before adding IFERROR.

Can I fill this formula down a whole import?

Yes, but first test rows with missing delimiters, extra spaces, blank cells, and unusual punctuation so the rule matches the real data.

Does this formula clean hidden spaces?

Some formulas use TRIM, but nonbreaking spaces and line breaks may need CLEAN or SUBSTITUTE before the final extraction step.