How to Extract Domain Names From URLs in Google Sheets

How to extract domain names from URLs in Google Sheets using a formula

Long website URLs often contain protocols, subdomains, page paths, tracking parameters, and other unnecessary information. When you are organizing leads, checking backlinks, cleaning an SEO report, or preparing website data for import, you may only need the clean domain name.

Fortunately, you do not need to edit every URL manually. You can use a simple Google Sheets formula to extract domain names from URLs automatically.

Quick answer: If the original URL is in cell A2, enter the following formula in another cell:

=IFERROR(LOWER(REGEXEXTRACT(TRIM(A2),"^(?:(?:https?|ftp)://)?(?:www\.)?([^/:?#]+)")),"")

This formula removes common protocols, removes www., ignores page paths and query parameters, converts the result to lowercase, and returns a clean domain or hostname.

Table of Contents

What Does Extracting a Domain Name Mean?

What Does Extracting a Domain Name Mean

A complete URL can contain several separate components. For example:

https://www.example.com/blog/article?id=25

In this URL:

  • Protocol: https://
  • Hostname: www.example.com
  • Clean domain: example.com
  • Path: /blog/article
  • Query parameter: ?id=25

Domain extraction means keeping the hostname or domain while removing the other URL components. The exact result depends on whether you want to keep subdomains such as shop.example.com or reduce everything to the registrable root domain, such as example.com.

When your source URLs are inconsistent, it is often helpful to clean them first. The guide on How to Clean Website URLs in Google Sheets explains how to standardize messy URL data before processing it further.

Best Formula to Extract Domain Names From URLs

Best Formula to Extract Domain Names From URLs

Assume your original URL is stored in cell A2. Enter this formula in B2:

=IFERROR(LOWER(REGEXEXTRACT(TRIM(A2),"^(?:(?:https?|ftp)://)?(?:www\.)?([^/:?#]+)")),"")

The formula uses several Google Sheets functions together:

  • TRIM removes unnecessary spaces before or after the URL.
  • REGEXEXTRACT finds and returns the hostname portion.
  • LOWER converts the result to lowercase for consistency.
  • IFERROR returns a blank cell when the value cannot be processed.

The regular expression also makes the protocol and www. optional. This means it can process URLs written in different formats.

Original URL Extracted Result
https://www.example.com/blog/post example.com
http://shop.example.com/product shop.example.com
www.sample.org/about sample.org
sample.net/contact?source=google sample.net
ftp://files.example.co.uk/folder files.example.co.uk

How to Extract Domain Names From URLs Step by Step

How to Extract Domain Names From URLs Step by Step
  1. Open the Google Sheets file containing your website URLs.
  2. Place the original URLs in column A, starting from cell A2.
  3. Add a heading such as Domain Name in cell B1.
  4. Select cell B2.
  5. Paste the domain extraction formula into the formula bar.
  6. Press Enter.
  7. Confirm that the clean domain appears in B2.
  8. Copy the formula down for the remaining rows, or use an array formula to process the entire column automatically.

After checking the results, you can copy the domain column and use Paste special → Values only when you need fixed text instead of live formulas.

How to Extract Domains From an Entire Column

How to Extract Domains From an Entire Column

Dragging a formula through hundreds or thousands of rows is unnecessary. Use ARRAYFORMULA to process a complete range automatically.

Enter this formula in B2:

=ARRAYFORMULA(IF(A2:A1000="","",IFERROR(LOWER(REGEXEXTRACT(TRIM(A2:A1000),"^(?:(?:https?|ftp)://)?(?:www\.)?([^/:?#]+)")),"Invalid URL")))

This version performs three useful checks:

  • Blank source cells remain blank.
  • Valid URLs return clean domains.
  • Values that do not match the expected format display Invalid URL.

A bounded range such as A2:A1000 can also be more efficient than applying a complex formula to every possible row in the spreadsheet. Increase the final row number when your dataset is larger.

How to Handle Subdomains and Root Domains

How to Handle Subdomains and Root Domains

The main formula keeps meaningful subdomains. For example, it converts:

https://store.example.com/products

into:

store.example.com

This is useful when different subdomains represent separate websites, departments, customer portals, or services.

Removing a Simple Subdomain

If B2 already contains a hostname, you can use this simple formula to keep only the last two labels:

=IFERROR(REGEXEXTRACT(B2,"([^.]+\.[^.]+)$"),B2)

For example, it converts blog.example.com into example.com.

Important: This simplified formula is not reliable for every domain extension. A domain such as example.co.uk contains a multi-part public suffix. The simple formula could incorrectly return co.uk.

Accurately identifying registrable domains across extensions such as .co.uk, .com.au, and private suffixes requires a maintained resource such as the Public Suffix List. For ordinary spreadsheet cleanup, keeping the full hostname is often safer than incorrectly removing part of a valid domain.

Alternative Domain Extraction Methods

Alternative Domain Extraction Methods

Method Best For Main Limitation
REGEXEXTRACT Fast, flexible URL extraction Requires understanding the matching pattern
REGEXREPLACE Removing known URL components Complex URLs may need several replacements
SPLIT Consistently formatted URLs Inconsistent protocols can shift the output columns
Google Apps Script Large or highly customized workflows Requires additional code and maintenance
Public Suffix List parser Accurate registrable-domain identification Not available as a standard Google Sheets formula

For most lead-generation, SEO, outreach, and data-cleaning spreadsheets, REGEXEXTRACT

Common Problems and Troubleshooting

Common Problems and Troubleshooting

The Formula Returns a Blank Cell

Check whether the source cell contains ordinary website text. Email addresses, sentences, malformed URLs, or unsupported values may not match the formula. Temporarily remove IFERROR to reveal the original error while troubleshooting.

The Result Still Contains a Subdomain

The main formula intentionally preserves subdomains other than www. This prevents important hosts such as app.example.com and shop.example.com from being incorrectly grouped together.

The Formula Produces an Array Expansion Error

An array formula needs empty cells below it. Delete any existing values in the output range and try again.

Some URLs Contain Spaces

The included TRIM function removes leading and trailing spaces. Spaces inside the URL may indicate damaged or incorrectly imported data and should be reviewed.

Your Spreadsheet Uses Semicolons

Some Google Sheets locales use semicolons instead of commas between function arguments. Replace the formula’s commas with semicolons when required by your spreadsheet locale.

Practical Uses for Extracted Domain Names

Practical Uses for Extracted Domain Names

Clean domain data can support many practical workflows:

  • Lead generation: Group multiple pages belonging to the same company.
  • Duplicate removal: Identify repeated websites even when their page paths differ.
  • SEO analysis: Organize referring pages by domain or hostname.
  • Backlink outreach: Avoid contacting the same website repeatedly.
  • CRM preparation: Create a standardized company-domain field before importing leads.
  • Email research: Compare business email domains with company websites.
  • Competitor research: Count how often specific domains appear in collected data.
  • Reporting: Present readable website information without long tracking URLs.

Key Takeaways

  • Use REGEXEXTRACT to isolate a domain or hostname from a URL.
  • Combine it with TRIM, LOWER, and IFERROR for cleaner results.
  • Use ARRAYFORMULA when processing an entire URL column.
  • Keep subdomains unless you have a clear reason to remove them.
  • Do not rely on a simple last-two-parts formula for every international domain extension.

Common Mistakes to Avoid

  • Removing every subdomain without checking whether it represents a separate service.
  • Using a formula designed only for URLs beginning with https://.
  • Leaving uppercase and lowercase versions of the same domain unstandardized.
  • Applying an array formula where the output column already contains data.
  • Assuming that every root domain ends with one simple extension such as .com.
  • Deleting the original URL column before verifying the extracted results.

Pro Tips and Best Practices

  • Keep the original URL column as a backup.
  • Convert domains to lowercase before checking for duplicates.
  • Use a separate validation column to flag suspicious results.
  • Test formulas on a small sample before processing thousands of rows.
  • Use bounded array ranges to reduce unnecessary calculations.
  • Paste the final results as values before exporting them to another system.
  • Review country-specific and private domain suffixes carefully before removing subdomains.

Frequently Asked Questions

What is the easiest way to extract a domain from a URL in Google Sheets?

Use REGEXEXTRACT with a pattern that ignores the protocol, www, path, port, query string, and fragment. Combining it with IFERROR, TRIM, and LOWER produces cleaner results.

Can Google Sheets remove HTTP and HTTPS from URLs?

Yes. A regular expression can treat http:// and https:// as optional parts of the URL and return only the hostname.

How do I extract domains from multiple URLs at once?

Use ARRAYFORMULA with the domain extraction formula. It automatically processes every populated cell in the specified range.

Can the formula remove www from a URL?

Yes. The provided formula treats www. as optional and excludes it from the extracted result.

Will the formula keep subdomains?

Yes. It keeps subdomains such as shop.example.com while removing only www. This is normally safer for data analysis.

How do I extract only the root domain?

A simple last-two-label formula works for domains such as example.com, but it can fail with suffixes such as co.uk. Accurate root-domain extraction requires public-suffix-aware processing.

Why does ARRAYFORMULA show a result expansion error?

The output cells below the array formula probably contain existing values. Clear the destination range so the results can expand.

Can I use this method for lead-generation data?

Yes. Domain extraction is useful for grouping businesses, finding duplicates, preparing CRM imports, cleaning company records, and organizing outreach lists.

Conclusion

Learning how to extract domain names from URLs can save significant time when working with SEO reports, lead lists, backlinks, CRM records, or website research.

The most practical method is to combine REGEXEXTRACT with TRIM, LOWER, and IFERROR. For larger datasets, add ARRAYFORMULA to process the entire URL column automatically.

Start with the main formula, test it on a few URLs, and review subdomains carefully before removing them. Once the results are verified, convert the formulas to values and continue with duplicate removal, company matching, or CRM preparation.

Try the formula in your own spreadsheet today, and bookmark WP Automation Guide for more practical Google Sheets, WordPress, SEO, and workflow-automation tutorials.

Comments