var re = /(?:^https?:\/\/(?:www\.)?)|(?:\/$)/g;
var strings = [
'http://foo.bar',
'http://foo.bar/',
'http://www.foo.bar',
'http://www.foo.bar/',
'https://foo.bar',
'https://foo.bar/',
'https://www.foo.bar',
'https://www.foo.bar/'
];
strings.forEach(function (string) {
console.log(string.replace(re, ''));
});