removing http:// or http:// and www
/^(?:https?:\/\/)?(?:www\.)?/i
where both https://
and www.
should be optional (?
) and non-capturing groups ((?:...)
).
var url = prompt("url: ");
url = url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, "").split('/')[0];
alert("url: " + url);
This will take care of http
, https
and www
url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, "").split('/')[0]