Regex module

compile

procedureextensionSource

Compiles pattern. The result says whether it was valid and, if not, the error says where it went wrong. Free the regex with free_regex.

Example↗
Regex :: #import "Extensions/Regex";

re, ok, error := Regex.compile("[a-z]+[0-9]");
assert(ok);
Regex.free_regex(*re);

_, ok, error = Regex.compile("(unclosed");
assert(!ok && error.message.count > 0);
compile :: (
    pattern: string,
    options := Options.{}
) -> (Regex, ok: bool, Error)

Compiles pattern. The result says whether it was valid and, if not, the error says where it went wrong. Free the regex with free_regex.

Parameters

pattern: string
the regular expression.
options := Options.{}
flags such as case-insensitive matching.

Returns

ok: bool
Example↗
Regex :: #import "Extensions/Regex";

re, ok, error := Regex.compile("[a-z]+[0-9]");
assert(ok);
Regex.free_regex(*re);

_, ok, error = Regex.compile("(unclosed");
assert(!ok && error.message.count > 0);

See also