Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Extract the domain name from a URL

/*
Write a function that when given a URL as a string, parses out just the domain 
name and returns it as a string. For example:

  * url = "http://github.com/carbonfive/raygun" -> domain name = "github"
  * url = "http://www.zombie-bites.com"         -> domain name = "zombie-bites"
  * url = "https://www.cnet.com"                -> domain name = cnet"
*/

const domainName = url => {
  let regExp = /http(s)?://|www./gi
  return url.replace(regExp, "").split(".")[0]
}

// With love @kouqhar
Source by www.codewars.com #
 
PREVIOUS NEXT
Tagged: #Extract #domain #URL
ADD COMMENT
Topic
Name
8+7 =