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#length

mtch.length → integer

Alias of #size

Returns the number of elements in the match array.

Example
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.length   #=> 5
m.size     #=> 5
See also #size #inspect #named_captures #hash also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1