n番めのマッチを見つける
# マッチするものの配列を作って,n番目を取り出す a = 'blue green red grern white'.scan(/\w+/) p "third color is #{a[2]}." if a.size>=2 # ループさせて,n番目にきたら処理する c = 0 'blue green red grern white'.gsub(/\w+/) { |x| c+=1; p "third color is #{x}." if c==3 } # 正規表現で p "third color is #{$3}." if 'blue green red grern white' =~ /\A(\w+)\s+(\w+)\s+(\w+)\s+/ # 結果はいずれも #=> "third color is red."