Google Sheets intermediate

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

Prompt

"Extract the domain from a column of URLs or email addresses using REGEXEXTRACT in Google Sheets"

Google Sheets
=REGEXEXTRACT(A1, "(?:https?://)?(?:www\.)?([^/]+)")

This formula extracts the domain name from a given URL or email address.

Step-by-step breakdown

  1. The REGEXEXTRACT function is used to apply a regular expression to the input.
  2. The pattern matches optional 'http://' or 'https://' and 'www.' prefixes.
  3. The capturing group '([^/]+)' captures the domain name until the next '/' or end of string.
  4. 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

Prompt

"https://www.example.com/path"

Google Sheets
example.com
Prompt

"user@example.org"

Google Sheets
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.