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:
http://www.example.com -> example.com
example.co.uk/dir/index.html -> example.co.uk
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 http[s] and the www. with an empty string (deleting it). Then I use substring to get the string between the beginning and the first / or if there is no / the whole string. My code looks like this:
REGEXP_SUBSTR(REGEXP_REPLACE(website_url, '^http[s]?://(www\.)?|^www\.', '', 1), '(.+?)(/|$)')
Everything works as expected, except the fact that my regex fails to exclude the /:
example.com/dir/index.html -> example.com/
I would like to get rid of the /. How do I do that?