title: Extracting rootdomains from URL string in Google Sheets
body: <p>Hi I am trying to extract the rootdomain from URL string in Google Sheets. I know how to get the domain and I have the formula to remove <code>www.</code> but now I realize it does not strip subdomain prefixes like 'mysite'.site.com; where <code>mysite</code> is not stripped from the domain name. </p>
  
  <p><strong>Question:</strong> How can I retrieve the <code>domain.com</code> <em>rootdomain</em> where the domain string contacts alphanumeric characters, then 1 dot, then alphanumeric characters (and nothing more)</p>
  
  <p>Formula so far in Google Sheets:</p>
  
  <pre><code>=REGEXREPLACE(REGEXREPLACE(D3923;"(http(s)?://)?(www\.)?";"");"/.*";"")
  </code></pre>
  
  <p>Maybe this can be simplified ... </p>
  
  <p>Test cases</p>
  
  <pre><code>    https://www.domain.com/ =&gt; domain.com
      https://domain.com/ =&gt; domain.com
      http://www.domain.nl/ =&gt; domain.com
      http://domain.de/ =&gt; domain.com
      http://www.domain.co.uk/ =&gt; domain.co.uk
      http://domain.co.au/ =&gt; domain.co.au
      sub.domain.org/ =&gt; sub.domain.com
      sub.domain.org =&gt; sub.domain.com
      domain.com =&gt; domain.com
      http://www.domain.nl?par=1  =&gt; domain.com
      https://www.domain.nl/test/?par=1  =&gt; domain.com
      http2://sub2.startpagina.nl/test/?par=1  =&gt; domain.com
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/rlH4X.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/rlH4X.jpg" alt="enter image description here"></a></p>