DEV Community

loading...

Discussion on: Daily Challenge #89 - Extract domain name from URL

Collapse
kvharish profile image
K.V.Harish

My solution in js

const domainName = (url) => {
  const match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);
  return (match && match.length > 2 && typeof match[2] === 'string' && match[2].length) ? match[2].split('.')[0] : null;
}