How we can find domain name using MySQL and regular expression

前端 未结 5 1841
花落未央
花落未央 2020-12-07 02:08

i am having some list of domains in the DB,like

http://www.masn.com/index.html
http://www.123musiq.com/index.html etc

w

5条回答
  •  醉梦人生
    2020-12-07 02:50

    Based on these answers, I came up with a similar solution, but it requires multiple queries.

    SELECT SUBSTRING_INDEX(url,'/',1) FROM table WHERE url NOT REGEXP '^[^:]+://';
    SELECT SUBSTRING_INDEX(url,'/',3) FROM table WHERE url REGEXP '^[^:]+://';
    

    The first query handles URLs without a protocol prefix. The second query handles URLs with a protocol prefix. Please note that these do not handle every valid URL, but should handle most proper URLs.

提交回复
热议问题