Skip to content

Instantly share code, notes, and snippets.

@lior-amsalem
Last active October 17, 2021 18:25
Show Gist options
  • Save lior-amsalem/225ed3fe632ba59bf8d2df5af6baf938 to your computer and use it in GitHub Desktop.
Save lior-amsalem/225ed3fe632ba59bf8d2df5af6baf938 to your computer and use it in GitHub Desktop.
Get domain name from a URL
/**
Developer comment
- we'll use regex to build few capturing groups with the next structure:
first: https://wwww
second: <the domain>
thrid: .<end of domain>
- than we pick the relevant group from the array (base on the code task requriement)
**/
function domainName(url){
return url.match(/^(https?:\/\/)?([w]+\.)?([a-z0-9-]+)\.[a-z]+/)[3];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment