Skip to content

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

instance method

MatchData#captures

captures → array

Returns the array of captures, which are all matches except m[0]:

Example
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
m[0]       # => "HX1138"
m.captures # => ["H", "X", "113", "8"]

Related: MatchData.to_a.

See also #byteoffset #deconstruct #begin #deconstruct_keys also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0