pub enum BytesMode {
Unicode,
Ascii,
UnicodeBytes,
}Expand description
Controls how the regex engine handles input encoding.
This enum represents the three valid combinations of the utf8 and unicode
flags in the underlying regex engine. Each variant has different trade-offs
between input flexibility and character class semantics.
The default is BytesMode::Unicode.
§Variants
§BytesMode::Unicode (default)
- Input is expected to be valid UTF-8
.matches any Unicode scalar value (except\nunlessdot_matches_new_lineis set)\w,\d,\smatch Unicode characters- Unicode properties like
\p{Letter}are available - Word boundaries (
\b) are Unicode-aware
§BytesMode::Ascii
- Input can be arbitrary bytes (no UTF-8 requirement)
.matches any single byte (except\nunlessdot_matches_new_lineis set)\wmatches[a-zA-Z0-9_]only (ASCII)\dmatches[0-9]only (ASCII)\smatches ASCII whitespace only- Unicode properties are not available
- Word boundaries (
\b) use ASCII-only word characters
Use this mode when matching raw binary data or filenames that may contain non-UTF-8 bytes and you don’t need Unicode character classes.
§BytesMode::UnicodeBytes
- Input can be arbitrary bytes (no UTF-8 requirement)
.matches Unicode scalar values (sequences of valid UTF-8 bytes)\w,\d,\smatch Unicode characters- Unicode properties like
\p{Letter}are available
Use this mode when the input may contain non-UTF-8 bytes but you still want
Unicode-aware character classes. Note that . will not match individual
non-UTF-8 bytes — it only matches valid UTF-8 codepoint sequences.
Variants§
Unicode
Unicode mode: input must be valid UTF-8, full Unicode support. (utf8=true, unicode=true)
Ascii
ASCII bytes mode: . matches any byte, character classes are ASCII-only.
(utf8=false, unicode=false)
UnicodeBytes
Unicode-aware bytes mode: input can be non-UTF-8, character classes
remain Unicode-aware. . matches Unicode scalar values only.
(utf8=false, unicode=true)