Don't use a regular expression here; there is no need, and it opens up the possibility of making mistakes. Use javascript's native URL constructor instead:
let url = new URL('https://stackoverflow.com/questions/7000995/jquery-removing-part-of-string-after-and-removing-too/7001040#7001040');
let hostname = url.hostname;
console.log(hostname); // stackoverflow.com