Extract hostname name from string

后端 未结 28 1498
情歌与酒
情歌与酒 2020-11-22 07:15

I would like to match just the root of a URL and not the whole URL from a text string. Given:

http://www.youtube.co         


        
28条回答
  •  情话喂你
    2020-11-22 08:07

    String.prototype.trim = function(){return his.replace(/^\s+|\s+$/g,"");}
    function getHost(url){
        if("undefined"==typeof(url)||null==url) return "";
        url = url.trim(); if(""==url) return "";
        var _host,_arr;
        if(-1

提交回复
热议问题