コード
var url1 = "http://192.168.55.33/nnnnnn/aaaaaaa";
var match = url1.match(/\/\/[^/]+(\/.*)/);
console.log(match ? match[1] : url1);
var url2 = "https://192.168.55.33/aaa/";
var match = url2.match(/\/\/[^/]+(\/.*)/);
console.log(match ? match[1] : url2);
var url3 = "http://192.168.55.33";
var match = url3.match(/\/\/[^/]+(\/.*)/);
console.log(match ? match[1] : url3);
const url1 = new URL("http://192.168.55.33/nnnnnn/aaaaaaa");
console.log(url1.pathname);
const url2 = new URL("https://192.168.55.33/aaa/");
console.log(url2.pathname);
const url3 = new URL("http://192.168.55.33");
console.log(url3.origin);
const url4 = new URL("http://192.168.55.33/nnnnnn/aaaaaaa");
console.log(url4.host);
結果
"/nnnnnn/aaaaaaa"
"/aaa/"
"http://192.168.55.33"
"192.168.55.33"
参考
URL {
href: 'https://example.com/path?param1=value1¶m2=value2',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/path',
search: '?param1=value1¶m2=value2',
searchParams: URLSearchParams { 'param1' => 'value1', 'param2' => 'value2' },
hash: ''
}