use literal notation (i.e. `/^https?.../`), since you don't have any variables in there. It's a lot faster. But in either case, this should be fairly trivial to do without regexp.
```
var urlParts = url.split('/');
var base = urlParts.slice(0,Math.min(5, urlParts.length-1)).join('/') + '/';
```
That takes care of the if-else below too