Skip to content

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

instance method

MatchData#size

mtch.size → integer

Returns the number of elements in the match array.

Example
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.length   #=> 5
m.size     #=> 5
See also #regexp #string #pre_match #to_a also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0