How to Extract Domain from URLs in Google Sheets?
Struggling to isolate domains from a list of URLs or email addresses? Use REGEXEXTRACT to simplify your data extraction process.
Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.
The formula
"Extract the domain from a column of URLs or email addresses using REGEXEXTRACT in Google Sheets"
=REGEXEXTRACT(A1, "(?:https?://)?(?:www\.)?([^/]+)")
This formula extracts the domain name from a given URL or email address.
Step-by-step breakdown
- The REGEXEXTRACT function is used to apply a regular expression to the input.
- The pattern matches optional 'http://' or 'https://' and 'www.' prefixes.
- The capturing group '([^/]+)' captures the domain name until the next '/' or end of string.
- The formula can be dragged down to apply to multiple rows of data.
Edge cases & warnings
- URLs without 'http://' or 'https://' will still be processed correctly.
- Email addresses will return the domain part after '@'.
- Subdomains will be included in the extracted domain.
- URLs with no domain (e.g., 'http://') will return an error.
Examples
"https://www.example.com/path"
example.com
"user@example.org"
example.org
Frequently asked questions
Can this formula extract domains from email addresses?
Yes, it extracts the domain part after '@'.
What happens if the URL is malformed?
The formula may return an error or an empty string.
Can I modify the regex to include subdomains?
Yes, the regex can be adjusted to capture subdomains as needed.
Can't find what you need?
Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.