var url="http://www.example.com:8080/animals/";//例
var host_domain = url.match(/^[httpsfile]+:\/{2,3}([0-9a-z\.\-:]+?):?[0-9]*?\//i)[1];
| URL | 抽出ホスト・ドメイン |
|---|
extractHostDomain関数
/**
* URLからホスト・ドメインを取得する。
* @param url URL
* @returns ホスト・ドメイン(例:www.example.com)
* @link http://stackoverflow.com/questions/8498592/extract-root-domain-name-from-string
*/
function extractHostDomain(url) {
var host_domain;
if (url.indexOf("://") > -1) {
host_domain = url.split('/')[2];
}
else {
host_domain = url.split('/')[0];
}
host_domain = host_domain.split(':')[0];
return host_domain;
}
| URL | 抽出ホスト・ドメイン |
|---|
(c)wacgance 2015-11-17