获取网站的 hostname

第一种: 

 

 

 

第二种: 正则匹配

let a = 'https://cnblogs.com/posts/edit'
let b = /^http(s)?:\/\/(.*?)\//
console.log(b.exec(a)[2])
// cnblogs.com

 

 

posted @ 2022-01-10 11:05  龙卷风吹毁停车场  阅读(145)  评论(0)    收藏  举报