Skip to content
instance method

MatchData#to_s

() -> ::String
to_s → string

Returns the matched string:

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

m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
# => #<MatchData "hoge" foo:"h" bar:"ge">
m.to_s # => "hoge"

Related: MatchData.inspect.

See also #to_a #values_at #string also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0