Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

MatchData#post_match

post_match → str

Returns the substring of the target string from the end of the first match in self (that is, self[0]) to the end of the string; equivalent to regexp global variable $':

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

Related: MatchData.pre_match.

See also #offset #pre_match #names #regexp also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0