我在JavaScript中有一些字符串:
示例:http://subdomain.domain.com/
我正在寻找可以从字符串中移除子域的正则表达式(或类似)表达式:http://domain.com
答案 0 :(得分:0)
url = window.location.href; // This will get you url from addressbar.
var url = "http://subdomain.domain.com/"; // sample for testing purpose. delete this line
var splitURL = url.split("."); // this will split the url based on .
console.log("http://"+splitURL[1]+"."+splitURL[2]); //removes the first Part that is stored in splitURL[0] and use only splitURL[1] and splitURL[2]
答案 1 :(得分:0)
我知道答案太迟了。但是,仍然有人遇到同样的问题,需要知道我们拥有一个parse-domain库,可以满足您的期望