我有这样一个字符串
item[3]>something>another>more[1]>here
hey>this>is>something>new
.
.
.
我想为每一行指示的每次迭代生成以下内容
item[3]>something>another>more[1]>here
something>another>more[1]>here
another>more[1]>here
more[1]>here
here
另一个例子:
hey>this>is>something>new
this>is>something>new
is>something>new
something>new
new
我想要一个正则表达式或某种方式来逐步删除 最左边的字符串,直到 >。
最佳答案
你可以使用 String.split()
来做到这一点:
var str = 'item[3]>something>another>more[1]>here',
delimiter = '>',
tokens = str.split(delimiter); // ['item[3]', 'something', 'another', 'more[1]', 'here']
// now you can shift() from tokens
while (tokens.length)
{
tokens.shift();
alert(tokens.join(delimiter));
}
另请参阅:Array.shift()
.
关于正则表达式 : how to remove string before > and including >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4665154/