struct Regex::MatchData

Overview

Regex::MatchData is the type of the special variable $~, and is the type returned by Regex#match and String#match. It encapsulates all the results of a regular expression match.

if md = "Crystal".match(/[p-s]/)
  md.string # => "Crystal"
  md[0]     # => "r"
  md[1]?    # => nil
end

Many Regex::MatchData methods deal with capture groups, and accept an integer argument to select the desired capture group. Capture groups are numbered starting from 1, so that 0 can be used to refer to the entire regular expression without needing to capture it explicitly.

Included Modules

Defined in:

luce/util.cr

Instance Method Summary

Instance Method Detail

def match : String #

Returns the whole match String

DEPRECATED Luce is removing its custom extensions. Use Regex::MatchData[0] instead. Will be removed with Luce v1.0