8.16.0.4
5.5.2 Full versus Partial Regexp Matching🔗ℹ

By default, a regexp matches an input string only when it matches the entire string.

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

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

> rx'any'.match("xy")

#false

A match to only part of the input can be enabled in either of two ways: by using rx_in to create the regexp, or by using the RX.match_in method to match to input. Using both rx_in and RX.match_in has the same effect as using only one of them. A partial match locates the the earliest point in the input where a successful match can start.

> rx'any'.match_in("xy")

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

> rx'any "x"'.match_in("xyxzx")

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

The bof and eof pattern operators explicitly match the beginning or end of an input. A pattern that uses those operators at the start and end will match the same with rx, rx_in, RX.match and RX.match_in.

> rx'bof any eof'.match_in("xy")

#false

The bol and eol operators match the start or end of a line, which includes the start and end of an input, but also includes the positions just after and just before a newline character.

> rx'bol any eol'.match_in("xy")

#false

> rx'bol any eol'.match_in("x\ny")

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

> rx'bol any eol'.match_in("\ny")

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

For partial matches or for locating capture groups within an input, RX.match_range and RX.match_range_in return a Range for each match, instead of the matching characters.

> rx'any "x"'.match_range_in("xyx")

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

> rx'any "x"* ($between: any) "x"*'.match_range("xxxxyxx")

RXMatch(0 .. 7, [4 .. 5], {#'between: 1})