On this page:
RXMatch
RXMatch.whole
RXMatch.captures
RXMatch.capture_  names
RXMatch.to_  list
RXMatch.get
8.15.0.12
12.2.4 Regexp Match Results🔗ℹ

class

class RXMatch(whole,

              captures :: List,

              capture_names :: Map)

Represents a successful match result from methods like RX.match. The whole field corresponds to the overall matched input (which can be a portion of the input for a rx_in or RX.match_in match, for example). The captures list contains portions of the overall match that correspond to capture groups in the pattern. The capture_names field maps capture-group names to indices, which count from 1.

The whole value and elements of captures are intended to be strings, byte strings, or ranges, depending on how the match is produced. For example, RX.match with a regexp in character mode on a string input will produce a RXMatch object whose whole is a string. The RX.match_range method produces a RXMatch object whose whole is a range.

A RXMatch object is Listable and Indexable. Its Listable.to_list conversion is same as [whole] ++ captures. Indexing by an integer accesses the same result as indexing the object’s list, but capture-group names (which are the keys of capture_names) can also be used as indices.

> rx'any "x" any'.match("axz")

RXMatch("axz", [], {})

> rx'any "x" any'.match("axz").whole

"axz"

> rx'any "x" any'.match(#"axz")

RXMatch(Bytes.copy(#"axz"), [], {})

> rx'byte "x" byte'.match("axz")

RXMatch(Bytes.copy(#"axz"), [], {})

> rx'any "x" any'.match_range("axz")

RXMatch(0 .. 3, [], {})

> def m = rx'($pre: any) "x" ($post: any)'.match("axz")

> m

RXMatch("axz", ["a", "z"], {#'post: 2, #'pre: 1})

> m[0]

"axz"

> m[1]

"a"

> m[#'pre]

"a"

method

method (rx :: RXMatch).to_list() :: List

Implements Listable.to_list, returning [RXMatch.whole(rx)] ++ RXMatch.captures(rx).

method

method (rx :: RXMatch).get(index)

Implements get operation of Indexable. The index argument normally satisfies NonnegInt or Symbol, but in general it can be a NonnegInt or any value that exists as a key in RX.capture_names(rx).