JavaScript-仅获取特定表达式后字符串的一部分

JavaScript-仅获取特定表达式后字符串的一部分,javascript,regex,Javascript,Regex,我有以下资料: var string = 'https://sub.example.com/dir/ https://sub.example.com/dir/v2.5/' var hostname = 'sub.example.com'; var hostname_match = hostname.replace(/\./g, '\\.'); string.replace(new RegExp('https\:\/\/'+hostname_match+'\/(.*)', 'g'), '/$1'

我有以下资料:

var string = 'https://sub.example.com/dir/ https://sub.example.com/dir/v2.5/'
var hostname = 'sub.example.com';
var hostname_match = hostname.replace(/\./g, '\\.');

string.replace(new RegExp('https\:\/\/'+hostname_match+'\/(.*)', 'g'), '/$1');
我想要的是得到以下信息:

/dir/ /dir/v2.5/

您只需替换
http://+hostname

var字符串class='1〕https://sub.example.com/dir/ https://sub.example.com/dir/v2.5/'
var hostname='sub.example.com';
让URL=string.split(“”)
.map(u=>u.replace('https://'+主机名,'))
console.log(URL)
//如果要使用空格分隔的字符串:
console.log(url.join(“”))
您可以使用

new RegExp('https://'+hostname_match+'/(\\S*)', 'g')
此处,
*
替换为匹配零个或多个非空白字符的
\S*

请参阅JS演示:

var字符串class='1〕https://sub.example.com/dir/ https://sub.example.com/dir/v2.5/'
var hostname='sub.example.com';
var hostname\u match=hostname.replace(/\./g,'\\.');
console.log(
替换(新的RegExp('https://'+主机名匹配+'/(\\S*),'g'),'/$1'))

);
Try
string.replace(新的RegExp('https://'+hostname\u match+'/(\\S*),'g'),'/$1')
我想要的是在:sub.example.com之后得到任何东西