var URL = "http://localhost:7001/www.facebook.com"; var newURL = URL.replace (/^[a-z]{4,5}:/{2}[a-z]{1,}:[0-9]{1,4}.(.*)/, '$1'); // http or https alert (newURL);