class Bytes::MatchData

A match in Bytes: as MatchData, with Bytes and byte offsets.

Bytes#match and Bytes#matches return them, and the blocks of Bytes#scan, Bytes#sub and Bytes#gsub with two parameters receive them. As in Ruby, a pattern with a named group captures with its named groups only. A negative index is no group (nil), unlike Ruby's.

m = b"key=v\xff".matches(/(\w+)=(.*)/)[0]
m[1]                   # => b"key"
m[2]                   # => b"v\xff"
m.begin(2)             # => 4
m[-1]                  # => nil

<prelude>:1608

Methods

def [](index: Int) -> Bytes?

The bytes of group index (0 is the whole match), or nil when the group took no part in the match, or there is no such group (a negative index included).

<prelude>:1614

def [](name: String) -> Bytes?

The bytes of the group named name, or nil when it took no part in the match. Raises IndexError when the pattern has no group of that name.

<prelude>:1618

def pre_match -> Bytes

The bytes before the match.

<prelude>:1620

def post_match -> Bytes

The bytes after the match.

<prelude>:1622

def captures -> Array[Bytes?]

The bytes of each group, without the whole match: nil for a group that took no part.

<prelude>:1625

def named_captures -> Hash[String, Bytes?]

The bytes of each named group by its name, nil for one that took no part.

<prelude>:1628

def names -> Array[String]

The names of the pattern's named groups, in order.

<prelude>:1630

def values_at(*indices: Int) -> Array[Bytes?]

The bytes of the groups at indices, as #[] gives each.

<prelude>:1632

def to_a -> Array[Bytes?]

The whole match followed by the bytes of each group.

<prelude>:1634

def size -> Int

The number of groups plus one, for the whole match.

<prelude>:1636

def to_s -> String

The whole match in its literal form, as Bytes#to_s gives it.

<prelude>:1638

def inspect -> String

The whole match and each group, as #<Bytes::MatchData b"ab" 1:b"a">.

<prelude>:1640

def begin(index: Int) -> Int?

The byte offset where group index starts (0 is the whole match), or nil when the group took no part. Raises IndexError when the pattern has no such group.

<prelude>:1644

def end(index: Int) -> Int?

The byte offset just past the end of group index (0 is the whole match), or nil when the group took no part. Raises IndexError when the pattern has no such group.

<prelude>:1648