Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从主机名获取域扩展名_Javascript - Fatal编程技术网

Javascript 从主机名获取域扩展名

Javascript 从主机名获取域扩展名,javascript,Javascript,使用regex从主机名中提取域扩展名(例如.com),而不是域名(例如google.com) 输入=>输出 www.google.com=>.com google.com=>.com google.co.uk=>.co.uk www.google.co.uk=>.co.uk sub.google.co.uk=>.co.uk 不是重复的请尝试以下操作: 函数getExtension(主机名){ 设e=hostname.slice(hostname.search('.')、hostname.leng

使用regex从主机名中提取域扩展名(例如
.com
),而不是域名(例如google.com)

输入=>输出

www.google.com
=>
.com

google.com
=>
.com

google.co.uk
=>
.co.uk

www.google.co.uk
=>
.co.uk

sub.google.co.uk
=>
.co.uk

不是重复的

请尝试以下操作:

函数getExtension(主机名){ 设e=hostname.slice(hostname.search('.')、hostname.length); 返回e;
}

您可以手动检查,然后检查前面出现的域段

即:
。[optionalCountryCode]

示例如下:

函数getTopDomain(域){ const topDomainExpression=/\w+(\.[a-z]{2,3})(\)。(ad)阿音音(A124)阿音(A124)阿音(A124)阿音(ad)阿音(A124)阿音(A124)阿音(A124)阿音(A124)阿音(A音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音)阿音(阿音)阿音(阿音)阿音)阿音(阿音)阿音)阿音(阿音)阿音(阿音)阿音(阿音)阿音)阿音(阿音)阿音)阿凯撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒撒ga