Last active
October 17, 2021 18:25
-
-
Save lior-amsalem/225ed3fe632ba59bf8d2df5af6baf938 to your computer and use it in GitHub Desktop.
Get domain name from a URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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