'/xxx/xxx/xxx/xxx/xxx/...', /xxx is greater than or equal to 2, how to get the first two '/xxx/xxx' in the simplest way (without defining extra variables) ?
a = a.split("/") a[1] a[2]
'/' + '/product/list/xxx/xxx'.slice(1).split('/', 2).join('/')
("/xxx/xxx/xxx/xxx/xxx/...".match(/^\/.*?\/[^\/]*/) || [])[0]
使用正则/(\/.*?\/.*?)\// var str = '/xxx/xxx/xxx/xxx/xxx/...'; var reg = /(\/.*?\/.*?)\//; console.log(str.match(reg)[1])
'/' + '/product/list/xxx/xxx'.slice(1).split('/', 2).join('/')