← index

Regex

inherits Object

A compiled regular expression -- the type of #/pattern/ literals. Match with ~, split with split:, substitute via String.replace:with:. Patterns use Rust's regex syntax.

#/ab+c/ ~ 'xabbbcy'     "* -> true

Instance methods

==:

Whether the argument is a Regex with the identical pattern text -- equivalent regexes written differently are unequal. A non-Regex is simply unequal, never an error.

#/a/ == #/a/     "* -> true
#/a/ == 'a'      "* -> false

native

match:

The first match of the pattern in the String argument, as a Match — or nil when the pattern does not match, so a nil-guard is the miss test. Capture groups (positional and named) ride on the Match.

(#/(\d+)-(\d+)/.match:'10-20').s     "* -> 10-20
#/x/.match:'abc'                      "* -> nil

native

split:

The pieces of the String argument between matches of the pattern, as a List of Strings (the pattern-based counterpart of String.splitString:).

#/,\s*/.split:'a, b,c'     "* -> #(a b c)

native

~:

Whether the pattern matches anywhere in the String argument (pattern ~ str). A non-String argument never matches (false, not an error).

#/\d+/ ~ 'order 66'     "* -> true
#/ab+c/ ~ 'xyz'         "* -> false

native