3.74. kink/regex/MATCH

3.74.1. type match

The result of a successful regex match or search.

`match` is a subtype of `group`. `match` represents the entire slice of the matched area.

See kink/regex/REGEX for regexes.

See kink/regex/GROUP for `group` type.

M.slice

`slice` returns the sliced str of the text where the regex matches.

Example:

:REGEX.require_from('kink/regex/')
:Regex <- REGEX.compile('0x[0-9a-f]+')
[:M] <- Regex.search('var x = 0xcafebabe;' 0)
stdout.print_line(M.slice.repr) # => "0xcafebabe"

M.from

`from` returns the pos from which the regex matches in the text.

Example:

:REGEX.require_from('kink/regex/')
:Regex <- REGEX.compile('0x[0-9a-f]+')
[:M] <- Regex.search('var x = 0xcafebabe;' 0)
stdout.print_line(M.from.repr) # => 8

M.to

`to` returns the pos to which the regex matches in the text.

Example:

:REGEX.require_from('kink/regex/')
:Regex <- REGEX.compile('0x[0-9a-f]+')
[:M] <- Regex.search('var x = 0xcafebabe;' 0)
stdout.print_line(M.to.repr) # => 18

M.have_group?(Name)

M.have_group? returns whether the match has the group named as `Name`.

Precondition:

• `Name` must be a str

Example:

:REGEX.require_from('kink/regex/')
:Regex <- REGEX.compile('(?<Hex>0x[0-9a-f]+)|(?<Binary>0b[01]+)')
[:M] <- Regex.search('var x = 0xcafebabe;' 0)
stdout.print_line(M.have_group?('Hex').repr)      # => true
stdout.print_line(M.have_group?('Binary').repr)   # => false
stdout.print_line(M.have_group?('Decimal').repr)  # => false

See kink/regex/GROUP for groups.

M.group(Name)

`group` returns a `group` val of the named group.

Precondition:

• `Name` must be a str

• The match must have the group named as `Name`.

Example:

:REGEX.require_from('kink/regex/')
:Regex <- REGEX.compile('(?<Var>[a-z]+) *= *(?<Num>[0-9]+)')
[:M] <- Regex.match('foo = 42')
stdout.print_line(M.group('Var').slice.repr)  # => "foo"
stdout.print_line(M.group('Num').slice.repr)  # => "42"

See kink/regex/GROUP for groups.

3.74.2. MATCH.is?(Val)

`is?` returns whether `Val` is a match val.