title: Get domain from URL in Oracle SQL
body: <p>I have a database that contains website URL's. From those URL's I'd like to extract the domain name. Here are two (quiet different) examples:</p>
  
  <pre><code>http://www.example.com       -&gt; example.com
  example.co.uk/dir/index.html -&gt; example.co.uk
  </code></pre>
  
  <p>In order to do this I am using a regular expression and the functions REGEXP_SUBSTR and REGEXP_REPLACE that Oracle provides. I am using replace to replace the preceding <code>http[s]</code> and the <code>www.</code> with an empty string (deleting it). Then I use substring to get the string between the beginning and the first <code>/</code> or if there is no <code>/</code> the whole string. My code looks like this:</p>
  
  <pre><code>REGEXP_SUBSTR(REGEXP_REPLACE(website_url, '^http[s]?://(www\.)?|^www\.', '', 1), '(.+?)(/|$)')
  </code></pre>
  
  <p>Everything works as expected, except the fact that my regex fails to exclude the <code>/</code>:</p>
  
  <pre><code>example.com/dir/index.html -&gt; example.com/
  </code></pre>
  
  <p>I would like to get rid of the <code>/</code>. How do I do that?</p>