Working with a long list of URLs can get messy quickly. One row might contain https://example.com/blog/article, another might contain www.example.com, and another could include tracking parameters that make the URL look even longer.
If all you need is the domain name, manually copying it from every URL is a slow and unnecessary job.
Google Sheets can extract domain names automatically with a simple formula. Once you know the right formula, hundreds or even thousands of URLs can be processed in seconds.
In this guide, we'll look at several ways to extract domains from URLs in Google Sheets. We'll start with the easiest approach and then move into methods that give you more control over subdomains, paths, protocols, and query parameters. These same text-parsing techniques can also be applied to other data cleanup tasks, like our step-by-step guide on How to Split Full Addresses in Google Sheets.
Why Extract Domain Names From URLs?
There are plenty of reasons you might want to turn full URLs into clean domain names.
For example, imagine you have a spreadsheet containing backlinks, competitor websites, referral URLs, or a list of sources. A full URL tells you exactly where a page is located, but sometimes you only need to know which website it belongs to.
Extracting the domain can make the data easier to analyze, filter, sort, and categorize.
Organizing Website Data
Domain extraction is particularly useful when you're working with SEO or marketing data.
Suppose your sheet contains 5,000 URLs. Instead of looking at long addresses such as:
https://www.example.com/resources/seo-guide?utm_source=google
you can turn them into:
example.com
That small change makes the spreadsheet much easier to read.
Creating a Clean Domain Column
A common workflow is to keep the original URL in one column and create a second column for the extracted domain.
For example:
| URL | Extracted Domain |
|---|---|
| https://example.com/about | example.com |
| https://www.google.com/search | google.com |
| https://blog.example.org/article | blog.example.org |
Keeping the original URL is a good idea because you can always return to the source data if something needs to be checked.
Understanding URL Structure
Before writing a formula, it helps to understand what you're actually extracting.
Consider this URL:
https://www.example.com/blog/article?id=25
It contains several pieces:
https://— the protocolwww.— a subdomainexample.com— the domain/blog/article— the path?id=25— a query parameter
The goal is usually to remove everything except the domain.
Domain vs. Full URL
A full URL identifies a specific location on a website. A domain identifies the website itself.
For example:
https://example.com/products/shoes
is the complete URL.
example.com
is the domain.
If you're analyzing websites rather than individual pages, the shorter domain is usually much more useful.
Subdomains and Paths
You should also decide whether you want to preserve subdomains.
For example:
blog.example.com
and
example.com
are not technically the same hostname.
If you're studying traffic sources or individual web properties, keeping blog. might be useful. If you're trying to group everything belonging to the same main website, you may want only example.com.
Extract a Domain With REGEXEXTRACT
One of the most flexible ways to extract a domain in Google Sheets is the REGEXEXTRACT function.
Assume your URL is stored in cell A2.
You can use:
=REGEXEXTRACT(A2,"(?:https?://)?(?:www\.)?([^/]+)")
This formula looks for the portion of the URL before the first slash.
Basic REGEXEXTRACT Formula
Let's break it down.
(?:https?://)?
allows the URL to contain either http:// or https://.
(?:www\.)?
allows www. to appear without including it in the extracted result.
([^/]+)
captures everything until the next /.
So this URL:
https://www.example.com/blog/post
returns:
example.com
That makes the formula useful for mixed URL lists where some addresses use HTTPS, some use HTTP, and others begin with www.
Handling HTTP and HTTPS
The https? portion is intentional.
The question mark means the s is optional, so the formula can recognize both:
http://example.com
and:
https://example.com
This is much safer than creating a formula that only works with HTTPS URLs.
Extract Domains With REGEXREPLACE
Another useful technique is REGEXREPLACE.
Instead of extracting the desired part directly, you can remove the parts you don't want.
For example:
=REGEXREPLACE(A2,"https?://(www\.)?","")
This removes the protocol and www. from the beginning.
However, that alone doesn't remove paths.
For a URL such as:
https://www.example.com/blog/article
you still need to remove /blog/article.
A more complete approach can be created by combining multiple cleanup operations.
Removing Protocols
If your URLs are consistent, you can remove the protocol with:
=REGEXREPLACE(A2,"^https?://","")
The ^ tells Google Sheets to look at the beginning of the text.
So:
https://example.com/page
becomes:
example.com/page
Removing Paths and Parameters
Once the protocol has been removed, you can remove everything starting with the first slash:
=REGEXREPLACE(REGEXREPLACE(A2,"^https?://(www\.)?",""),"/.*$","")
The result is:
example.com
This method is especially useful when you want to customize the cleanup process.
Use SPLIT to Process Simple URLs
If your URLs are very predictable, SPLIT can be a straightforward solution.
For example, if a cell contains:
example.com/page
you could use:
=INDEX(SPLIT(A2,"/"),1)
This separates the text wherever a slash occurs and returns the first piece.
When SPLIT Works Best
SPLIT is great when your data is already relatively clean.
For example, if every value looks like:
example.com/page
it works nicely.
But real-world URL lists aren't always that cooperative. You may encounter https://, www., query strings, ports, or other URL variations.
For messy or inconsistent data, REGEXEXTRACT is generally the more flexible choice.
Extract Domains From an Entire Column
What if you have hundreds of URLs?
You don't want to manually enter a formula into every row.
That's where ARRAYFORMULA can help.
Suppose URLs are stored in column A, beginning at A2. You can place this formula in B2:
=ARRAYFORMULA(IF(A2:A="","",REGEXEXTRACT(A2:A,"(?:https?://)?(?:www\.)?([^/]+)")))
Now Google Sheets can process the column automatically.
Using ARRAYFORMULA
The advantage is simple: add another URL to column A, and the formula can automatically produce its domain in column B.
This is particularly convenient for ongoing spreadsheets.
Instead of repeatedly dragging formulas downward, you create one formula that handles the entire range.
Skipping Blank Cells
The IF(A2:A="","",...) portion prevents empty rows from producing unwanted results.
Without it, your sheet may become filled with errors or unnecessary output.
For a working spreadsheet, small details like this make a big difference in keeping your data clean.
Remove www From Domain Names
Sometimes you want to keep the hostname exactly as it appears. Other times, you want standardized domains.
For example:
www.example.com
and
example.com
may need to be treated as the same website for your analysis.
You can remove www. using:
=REGEXREPLACE(B2,"^www\.","")
If B2 contains www.example.com, the result becomes:
example.com
Formula for Removing www
You can also combine extraction and cleanup into one formula:
=REGEXREPLACE(REGEXEXTRACT(A2,"(?:https?://)?([^/]+)"),"^www\.","")
This first extracts the hostname and then removes www..
That gives you a standardized result without requiring an extra column.
Extract the Root Domain Instead
Here's where things become slightly more complicated.
Consider:
https://blog.example.com/article
The hostname is:
blog.example.com
But the root domain is:
example.com
These are different concepts.
Understanding Root Domains
A root or registrable domain generally refers to the main domain beneath the relevant public suffix.
For example:
store.example.com
has a hostname of store.example.com, while the main domain is generally example.com.
A basic Google Sheets regex can remove common subdomains, but there is no universal two-part formula that correctly identifies every public suffix worldwide.
Domains such as:
example.co.uk
illustrate why this matters.
If you need highly accurate root-domain parsing across international public suffixes, a dedicated domain-parsing service or a public suffix list may be more appropriate than a simple spreadsheet formula.
Clean and Standardize Extracted Domains
Extraction is only half the job.
If you're preparing data for analysis, you should standardize the results afterward.
You may encounter:
www.example.comexample.comEXAMPLE.COMexample.com/example.com
These values may represent the same website but look different to Google Sheets.
Remove Trailing Characters
If your extracted data contains unnecessary spaces, TRIM can help:
=TRIM(B2)
For consistent capitalization, use:
=LOWER(B2)
You can combine both:
=LOWER(TRIM(B2))
This turns something like:
Example.COM
into:
example.com
Standardization is especially important before using formulas such as COUNTIF, UNIQUE, or QUERY to analyze domains.
Common Errors and How to Fix Them
Even a simple formula can produce unexpected results if the source data isn't consistent.
A URL may be missing a protocol, contain a port number, or have unusual formatting.
Invalid or Empty Results
If REGEXEXTRACT returns an error, first inspect the URL.
For example, a completely blank cell doesn't contain anything for the regex to extract.
You can protect a formula with IFERROR:
=IFERROR(REGEXEXTRACT(A2,"(?:https?://)?(?:www\.)?([^/]+)"),"")
Now an invalid value produces a blank result instead of an error message.
This is useful when processing large datasets where you don't want a few problematic rows to interrupt your analysis.
Which Google Sheets Formula Should You Use?
There's no single formula that's perfect for every spreadsheet.
If you have ordinary URLs with different protocols and paths, REGEXEXTRACT is usually the best starting point.
If you need to remove specific pieces of a URL, REGEXREPLACE gives you more control.
If your URLs are extremely simple, SPLIT may be all you need.
For large datasets, combining these functions with ARRAYFORMULA can save a considerable amount of time.
Choosing the Right Method
Here's a practical rule of thumb:
Use REGEXEXTRACT when you want to identify and capture the domain.
Use REGEXREPLACE when you want to clean or transform the URL.
Use SPLIT when the URL structure is simple and predictable.
Use ARRAYFORMULA when you need to process an entire column automatically.
The best formula isn't necessarily the longest one. It's the one that matches the structure of your data.
Conclusion
Extracting domain names from URLs in Google Sheets doesn't have to be a tedious manual task. With functions such as REGEXEXTRACT, REGEXREPLACE, SPLIT, TRIM, and ARRAYFORMULA, you can turn messy URL lists into clean, useful datasets.
For most situations, start with:
=REGEXEXTRACT(A2,"(?:https?://)?(?:www\.)?([^/]+)")
Then customize the formula if you need to preserve subdomains, remove www., process entire columns, or handle unusual URL structures.
The key is to decide what you mean by “domain” before building your formula. Do you want the hostname, the domain including a subdomain, or the root domain? Once that's clear, the right Google Sheets approach becomes much easier to choose.
Frequently Asked Questions
1. What is the easiest way to extract a domain from a URL in Google Sheets?
The easiest flexible option is REGEXEXTRACT. If the URL is in A2, try:
=REGEXEXTRACT(A2,"(?:https?://)?(?:www\.)?([^/]+)")
It extracts the hostname while ignoring the HTTP or HTTPS protocol and optional www. prefix.
2. Can Google Sheets extract domains from an entire column?
Yes. You can combine REGEXEXTRACT with ARRAYFORMULA to process many URLs automatically.
For example:
=ARRAYFORMULA(IF(A2:A="","",REGEXEXTRACT(A2:A,"(?:https?://)?(?:www\.)?([^/]+)")))
This is useful when you're working with large URL datasets.
3. How do I remove www from a domain in Google Sheets?
Use REGEXREPLACE:
=REGEXREPLACE(A2,"^www\.","")
If the cell contains www.example.com, the result will be example.com.
4. Can I extract a domain without https:// or http://?
Yes. A formula such as:
=REGEXEXTRACT(A2,"(?:https?://)?(?:www\.)?([^/]+)")
is designed to work whether the URL starts with http://, https://, or neither.
5. Can Google Sheets extract the root domain from a subdomain?
It can handle simple cases with additional formulas, but identifying root domains perfectly across every country-code and multi-level public suffix is more complicated.
For example, blog.example.com can usually be reduced to example.com, but domains such as example.co.uk require more careful public-suffix handling.
6. How can I prevent formula errors when a URL is invalid?
Wrap the extraction formula with IFERROR.
For example:
=IFERROR(REGEXEXTRACT(A2,"(?:https?://)?(?:www\.)?([^/]+)"),"")
This returns a blank cell instead of an error when Google Sheets can't find a matching domain.
7. Should I keep the original URLs after extracting domains?
Yes. It's generally a good practice to preserve the original URL in one column and put the extracted or standardized domain in another.
That gives you a reliable source column while allowing you to analyze the cleaned data separately.

Comments
Post a Comment