DEV Community

loading...

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

Collapse
kjhank profile image
Krzysztof Hankiewicz

Quick & dirty ugly chain if you don't want to research regex:

const domainName = (domain) => domain.split('://')[1].split('/')[0].includes('www.') ? domain.split('://')[1].split('/')[0].split('www.')[1].split('.')[0] : domain.split('://')[1].split('/')[0].split('.')[0]