Javascript 从主机名获取域扩展名
使用regex从主机名中提取域扩展名(例如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
.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