LEVIATHAN v962456e · 962456eee1

Standard Library

struct RegexOptions

Options that change how a pattern is interpreted: ASCII case folding, line anchors and whether . crosses line breaks.

since 0.1.0-alpha.1linuxwindowswasm

Overview

Pass one to a Regex constructor or to a regex:: function, either built with named arguments or as a flag string of the letters i, m and s. All flags are off by default.

Examples

Each option on its own

Regex plain = Regex("hello");
Regex loose = Regex("hello", RegexOptions(ignoreCase: true));
console.writeln(plain.isMatch("Say HELLO"));
console.writeln(loose.isMatch("Say HELLO"));
Regex lines = Regex("^b", RegexOptions(multiline: true));
console.writeln(lines.isMatch("a\nb"));
Regex dot = Regex("a.b", RegexOptions(dotAll: true));
console.writeln(dot.isMatch("a\nb"));
false
true
true
true

Constructors

new

new(bool ignoreCase = false, bool multiline = false, bool dotAll = false)

Create options. Every flag defaults to false, so name only the ones you want.

Parameters

ignoreCase
Match letters regardless of ASCII case.
multiline
Let ^ and $ match at line breaks.
dotAll
Let . match a line break.

Examples

Named arguments

RegexOptions o = RegexOptions(ignoreCase: true, dotAll: true);
console.writeln(o.ignoreCase);
console.writeln(o.multiline);
console.writeln(o.dotAll);
true
false
true

Fields

dotAll

bool dotAll

When true, . also matches a line break (it normally does not). Flag letter s.

ignoreCase

bool ignoreCase

When true, letters match regardless of ASCII case. Only the letters A to Z are folded; other characters are compared exactly. Flag letter i.

multiline

bool multiline

When true, ^ also matches right after a line break and $ right before one, instead of only at the start and end of the whole text. Flag letter m.

See also

  • Regex — A compiled regular expression.