The javascript used by Google Scripts does not include the URI API library for parsing URLs. It also does not support complex (perl-like backwards looking) regular expressions. As far as I know you can't import public libraries. This makes it hard, verbose and unreliable to parse out URL elements.
However it does support web calls through URLFetchApp and the REST API. Is there a parsing server out in the internet that hosts the URI API, which can be called by URLFetchApp or using the built in REST API? I can not find one easily. Other solutions welcome.
I have a working solution only for US based URLs. International URLs break my regEx. I prefer using a robust solution not dependent on regEx.
If you want to know the problem dealing with.... I need to compare two URLs and see if the 2nd url is a on a subdomain, or directory or same as the home page.
function scoreURL (urlOne,urlTwo){
let regexSubdomain = /(?:http[s]?:\/\/)?([^\/\s]+)(\/.*)?/;
var urlOneArray = urlOne.split(regexSubdomain);
var urlTwoArray = urlTwo.split(regexSubdomain);
var subdomainOne = urlOneArray[1].replace(new RegExp('www.','i'),'')
var subdomainTwo = urlTwoArray[1].replace(new RegExp('www.','i'),'')
// return -1 if landing page is on sub domais, 0 if landing page is separate page , 1 if landing page is home page
if (subdomainOne === subdomainTwo) {
if (urlOneArray[2] === urlTwoArray[2])
{return (1);} else {return(0);}
} else return (-1);
}