Regexp
If the integer nth is 0, returns the matching string ($&). Otherwise, returns the substring matching the nth set of parentheses ($1, $2, ...). When there are no corresponding parentheses or no matches, returns nil.
Because Regexp.last_match, with no arguments, returns nil when the entire regular expression does not match, the format last_match[1] will throw a NameError exception. On the other hand, last_match(1) returns nil.
Last updated