我有一个 hostName 字符串,该字符串可能是或可能不是完全限定的域名。
hostName
hostName = host1.abc.com OR hostName = host1
万一 主机名 是一个完全限定的域名,那么我只需要捕获其中的第一部分 host
主机名
host
host = host1
"" 当 主机名
""
const host = hostName.substring(0, hostName.indexOf('.'));
const host = hostName.split('.')[0];
否则
const idx = hostName.indexOf('.');
const host = idx > 0 ? hostName.substring(0, idx) : hostName;