正则表达式 : how to remove string before > and including >

标签 javascript regex

我有这样一个字符串

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() .

Demo →

关于正则表达式 : how to remove string before > and including >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4665154/

相关文章:

regex - 为什么这个正则表达式替换不起作用?

javascript - 使用正则表达式结果集的一部分进行匹配

javascript - 有没有办法将 Google 文档分割成多个 PDF?

javascript - 如何用类关闭 jquery 对话框?

javascript - 如何编写 Websockets/AJAX 代码以实现频繁的数据库更新?或者有更好的方法吗?

java - 模式匹配 : Matching a String with a pattern

php - 如何在 php 中检查一个字符串是否连续两次包含相同的字母?

javascript - 用 javascript 封装大的 Markdown 段落

javascript - 将命名函数存储在具有不同名称的变量中

javascript - 将附加数据发送到 KendoUI DataSource 并在 dataBound 事件中使用它