How we can find domain name using MySQL and regular expression

前端 未结 5 1840
花落未央
花落未央 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:37

    If you're not afraid of installing MySQL extensions (UDFs), then there's a UDF you can use that does exactly this while respecting different top-level domains like "google.com" and "google.co.uk", and handles a whole ton of other edge cases

    https://github.com/StirlingMarketingGroup/mysql-get-etld-p1

    select`get_etld_p1`('http://a.very.complex-domain.co.uk:8080/foo/bar');-- 'complex-domain.co.uk'
    select`get_etld_p1`('https://www.bbc.co.uk/');-- 'bbc.co.uk'
    select`get_etld_p1`('https://github.com/StirlingMarketingGroup/');-- 'github.com'
    select`get_etld_p1`('https://localhost:10000/index');-- 'localhost'
    select`get_etld_p1`('android-app://com.google.android.gm');-- 'com.google.android.gm'
    select`get_etld_p1`('example.test.domain.com');-- 'domain.com'
    select`get_etld_p1`('postgres://user:pass@host.com:5432/path?k=v#f');-- 'host.com'
    select`get_etld_p1`('exzvk.omsk.so-ups.ru');-- 'so-ups.ru'
    select`get_etld_p1`('http://10.64.3.5/data_check/index.php?r=index/rawdatacheck');-- '10.64.3.5'
    select`get_etld_p1`('not a domain');-- null
    

提交回复
热议问题