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

length

Alias of #size

Returns size of the match array:

Example
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
m.size # => 5

MatchData#length is an alias for MatchData.size.

See also #size #inspect #match #hash also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0