Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

MatchData#captures

mtch.captures → array

Returns the array of captures; equivalent to mtch.to_a[1..-1].

Example
f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
f1    #=> "H"
f2    #=> "X"
f3    #=> "113"
f4    #=> "8"
See also #begin #end #[] #eql? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1