method

last_match

v1_8_7_330 - Show latest stable - Class: Regexp
last_match(...)
public

The first form returns the MatchData object generated by the last successful pattern match. Equivalent to reading the global variable $~. The second form returns the nth field in this MatchData object.

/c(.)t/ =~ 'cat'       #=> 0
Regexp.last_match      #=> #<MatchData:0x401b3d30>
Regexp.last_match(0)   #=> "cat"
Regexp.last_match(1)   #=> "a"
Regexp.last_match(2)   #=> nil