javascript - js string interception
代言
代言 2017-06-12 09:27:43
0
4
786

'/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) ?

代言
代言

reply all(4)
洪涛
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])
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template