可能重复:
Is there an equivalent of Array#find_index for the last index in ruby?红宝石线切割
我有一个字符串
story = "Everything before the word irrelevent is irrelevent. Everything after it is relevent"
我想之前删除一切(包括)的“中最后一次出现无关紧要”。我如何在ruby中做到这一点。
可能重复:
Is there an equivalent of Array#find_index for the last index in ruby?红宝石线切割
我有一个字符串
story = "Everything before the word irrelevent is irrelevent. Everything after it is relevent"
我想之前删除一切(包括)的“中最后一次出现无关紧要”。我如何在ruby中做到这一点。
story.gsub /.*irrelevent/, ''
此外,您还拼错无关
您可以使用这样的事情:
story.split(/\birrelevent\b/).last
,你可以使用'story.split(/ irrelevent /)。last'删除点 –
'story.split(/ \ birrelevent \ b [^ \ w \ d] + /)。last' –
正则表达式的工作:http://rubular.com/r/xj9NB7Hekq
在Ruby:story[/irrelevent(?:(?!irrelevent).)*$/]
但不删除最后一次出现。但它是微不足道的。 – Alexander
[你尝试过什么?](http://whathaveyoutried.com) –
http:// stackove rflow.com/questions/3553947/is-there-an-equivalent-of-arrayfind-index-for-the-last-index-in-ruby – nhahtdh