var url = 'http://sitename.ru/path/name/?search'; url = url.replace(/^(https?:\/\/[^\/]+\/)[^?#]+/, '$1'); alert(url);