Skip to content
instance method

MatchData#pre_match

() -> ::String
pre_match → string

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

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

Related: MatchData#post_match.

See also #post_match #regexp #offset #size also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0