Is there a way to get the domain without the hostname from the URL?
I have the following list
const value1 = 'https://localhost:4200/~';
const value2 = 'https://hoge.com/~';
const value3 = 'https://www.hoge.com/~';
const value4 = 'https://wwwtest.hoge.com/~';
const value5 = 'https://www-test.hoge.com/~';
the answer i'm looking for
'localhost:4200/~'; //value1
'hoge.com/~'; //value2
'hoge.com/~'; //value3
'hoge.com/~'; //value4
'hoge.com/~'; //value5
I tried the following method, but the answer was not correct.
function hogeReplace(value: string): string {
return value.replace(/^https?:\/\/|www.*\./g, '');
}
console.log(hogeReplace(value1)); // localhost:4200/~
console.log(hogeReplace(value2)); // hoge.com/~
console.log(hogeReplace(value3)); // com/~
console.log(hogeReplace(value4)); // com/~
console.log(hogeReplace(value5)); // com/~
someone answer?