RoadRunner RoadRunner - 1 month ago 7
MySQL Question

How to select string between characters?

I made this table:

Table (Websites)

WebsiteID | WebsiteName
2324442 'http://www.samsung.com/us/'
2342343 'https://www.microsoft.com/en-au/windows/'
3242343 'http://www.apple.com/au/iphone/'


And I want to be able to
SELECT
the domain names from this table.

Something like this:

WebsiteName
'www.samsung.com'
'www.microsoft.com'
'www.apple.com'


Is there a string method I can use for this? Like splitting the string between
//
and
/
.

Answer

You can use SUBSTRING_INDEX() :

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(websiteName, '//', -1),
                   '/', 1)
FROM table
Comments