Answers for "javascript get hostname from url string"

5

javascript get domain name from string

const url = 'https://www.mydomain.com/blog?search=hello&world';
const domain = (new URL(url)).hostname.replace('www.','');
Posted by: Guest on August-28-2020
0

js get hostname from url

url = "http://www.example.com/path/to/somwhere";
urlParts = /^(?:\w+\:\/\/)?([^\/]+)([^\?]*)\??(.*)$/.exec(url);
hostname = urlParts[1]; // www.example.com
path = urlParts[2]; // /path/to/somwhere
Posted by: Guest on April-09-2021

Code answers related to "javascript get hostname from url string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language