title: Trim URL to ROOT/SUBDOMAIN with Excel
body: <p>I need to trim URL's in Microsoft Excel to the root domain and to the subdomain.</p>
  
  <p><strong>A1</strong> = Contains <code>https://blog.example.com/page/</code><br>
  <strong>B1</strong> = Should result in <code>example.com</code><br>
  <strong>C1</strong> = Should result in <code>blog.example.com</code><br></p>
  
  <p>Two formulas removing http, https, .www and PATH. The first version (<strong>B1</strong>) should also remove SUBDOMAIN. </p>
  
  <p>I only have <em>one</em> formula right now: </p>
  
  <p><code>=MID(SUBSTITUTE(A2;"www.";"");SEARCH(":";A2)+3;SEARCH("/";SUBSTITUTE(A2;"www.";"");9)-SEARCH(":";A2)-3)</code></p>
  
  <p><code>https://example.com/page/page</code> results in <code>example.com</code><br>
  <code>http://www.example.com/page/page</code> results in <code>example.com</code><br>
  <code>http://blog.example.com/page/</code> results in <code>blog.example.com</code><br>
  <code>example.com/page</code>  results in  <code>#VALUE!</code><br>
  <code>www.example.com/page</code>  results in   <code>#VALUE!</code><br></p>
  
  <p>As you can see in the sample above I get good results. But it dosen't work without http or https. Also this version keeps subdomain. </p>