js 获取地址第1个斜杠后的内容或地址前一部分

var value = "https://www.baidu.com/20210922/95b22ab5034b2d0f.jpg";
const str = value.split("https://"); //https://进行分割,
const index = str[1].indexOf("/")+1; //indexOf 获取第一个斜杠的索引,
console.log(str[1].substring(index)); //substring 截取,

//获取前面的域名

var i = "https://www.baidu.com/20210922/95b22ab5034b2d0f.jpg";
console.log(i.match(/^(?:[^/]|//)*/));

qq 891451702
原文地址:https://www.cnblogs.com/duoyan/p/15319748.html