struct Regex::MatchData
- Regex::MatchData
- Struct
- Value
- Object
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
- Regex::PCRE2::MatchData