How to Extract Only the Domain Name from a URL in Google Sheets Using REGEXEXTRACT

If you are managing an SEO campaign, building a backlink database, or analyzing website traffic, you likely have a spreadsheet filled with hundreds of messy, inconsistent URLs. Some start with http://, some start with https://www., and many have long, trailing sub-directories like /blog/article-name?tracking=123.

Sorting or categorizing this data is impossible unless you can strip away all the garbage and extract just the clean, root domain name (e.g., turning https://www.digitash.com/article into just digitash.com). Doing this manually with “Find and Replace” is a nightmare because the prefixes and suffixes are completely different on every row.

You can solve this instantly by using the REGEXEXTRACT function paired with a powerful Regular Expression to automatically isolate the domain name, no matter how messy the URL is.

The Scenario

Assume you have a list of raw URLs in Column A starting at cell A2. You want the clean domain name to appear in Column B.

Step 1: The Magic Formula

Click on cell B2 and paste the following formula exactly as written:

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

Step 2: Understanding How it Works (The Regex Breakdown)

Regular Expressions (Regex) look like absolute gibberish, but they follow strict mathematical logic. Here is exactly how this formula cuts through the garbage:

  • ^ : This tells the formula to start looking at the very beginning of the URL.
  • (?:https?:\/\/)? : This looks for http:// or https://. The ? at the end makes it optional, so the formula won’t break if the URL doesn’t have the protocol. The ?: means “ignore this part, don’t extract it.”
  • (?:www\.)? : This looks for www. and also makes it optional and ignored.
  • ([^\/]+) : This is the core engine. The parentheses tell the formula: “This is the exact part I want to extract.” The [^\/]+ means: “Grab every single character you see until you hit the very first forward slash (/), and then stop immediately.”

When the formula reads https://www.apple.com/macbook/pro, it ignores the https, ignores the www, grabs apple.com, and stops immediately before the /macbook.

Step 3: Handling Empty Cells and Errors

If you drag this formula down an entire column, any blank cells in Column A will result in an ugly #N/A error in Column B. To make your spreadsheet look professional, you should wrap the entire formula in an IFERROR statement.

Update your formula in cell B2 to this:

=IFERROR(REGEXEXTRACT(A2, "^(?:https?:\/\/)?(?:www\.)?([^\/]+)"), "")

Now, if the formula encounters a blank cell or a severely broken URL that it cannot parse, it will simply output a clean, blank cell instead of a glaring red error message. You can confidently drag this formula down 10,000 rows to instantly clean your entire SEO database.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.