function explode(url, part) { let urlParts = url.replace('http://','').replace('https://','').split(/[/?#]/); return urlParts[part]; } let url = 'http://scratch99.com/web-development/javascript/', domain = explode(url, 0), dir = explode(url, 1), subdir = explode(url, 2) console.log(domain); console.log(dir); console.log(subdir);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter