我有一個字符串定義如下:正則表達式匹配到一個數組
st = "The quick {{brown}} fox jumped over the {{fence}}."
要刪除{{}},我做了以下內容:
st.gsub(/{{(.*?)}}/, '\1')
=> "The quick brown fox jumped over the fence."
我想現在要做的就是把每一個匹配的正則表達式到一個數組中的項目,從而使最終的結果是這樣的:在廣告
arr = []
puts arr => ['brown', 'fence']
puts st => "The quick brown fox jumped over the fence."
謝謝萬斯。
不能接受這個答案10分鐘,但是這就是答案,它在我的IRB工作正常。很快會接受:-)謝謝! – 2014-10-26 14:08:24