嗨,我有一个小的
ruby函数,分割出一个
Ruby数组,如下所示: –
def rearrange arr,from,to sidx = arr.index from eidx = arr.index to arr[sidx] = arr[sidx+1..eidx] end arr= ["Red","Green","Blue","Yellow","Cyan","Magenta","Orange","Purple","Pink","White","Black"] start = "Yellow" stop = "Orange" rearrange arr,start,stop puts arr.inspect #=> ["Red",["Cyan","Orange"],"Black"]
我需要在我的开始使用正则表达式并停止搜索,例如
开始=“/大喊/”
停止=“/ Ora /”
有没有一种简单的方法在Ruby中做到这一点?