#[non_exhaustive]pub enum RegexErrorKind {
Show 33 variants
TrailingBackslash,
UnknownEscape,
InvalidHexEscape,
InvalidCodePoint,
MalformedProperty,
UnknownProperty,
UnclosedGroup,
UnmatchedParen,
UnknownGroup,
UnknownOption,
UnclosedComment,
InvalidGroupName,
DuplicateGroupName,
MixedGroups,
NumberedBackrefWithNamedGroups,
UndefinedGroupName,
BackreferenceOutOfRange {
group: u32,
groups: u32,
},
UnclosedClass,
EmptyClass,
UnescapedBracket,
InvalidRange,
UnknownPosixClass,
NothingToRepeat,
RepeatedQuantifier,
AmbiguousQuantifier,
InvalidInterval,
QuantifiedAssertion,
LookbehindNotFixed,
CaptureInLookbehind,
TooDeep,
NulCharacter,
BackslashBeforeDigit,
TooManyGroups,
}Expand description
What is wrong with a pattern. See RegexError.
Every variant names a construct that Oniguruma refuses, that some engine loading TextMate grammars refuses, or that engines read differently. The fix for each is in its documentation.
§Examples
use textmate_lang::{RegexErrorKind, validate_regex};
assert_eq!(validate_regex("x{2}?").unwrap_err().kind, RegexErrorKind::AmbiguousQuantifier);
assert_eq!(validate_regex("[z-a]").unwrap_err().kind, RegexErrorKind::InvalidRange);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
TrailingBackslash
The pattern ends with a lone \. Write \\ for a backslash.
UnknownEscape
An escape outside the subset: an unknown letter (\q, \K, \R), an
octal escape (\0, \012), \b inside a class (a backspace there, a
word boundary elsewhere), a back-reference inside a class, or a
backslash before a control or non-ASCII character. Write the character
itself, or \xHH / \x{H...} for a code point.
InvalidHexEscape
\x is not followed by exactly two hex digits or { one to eight hex
digits }, or \u is not followed by exactly four hex digits.
InvalidCodePoint
A hex escape names a surrogate or a value above U+10FFFF, or \xHH
names a byte above 7F (Oniguruma reads that as a raw UTF-8 byte). Use
\x{HH} for code points above 7F.
MalformedProperty
\p or \P is not followed by {name} (the one-letter form \pL is
not portable).
UnknownProperty
\p{...} names a property outside the supported list (Unicode
general categories, a set of scripts and binary properties, and the
POSIX classes). See docs/API.md#regex-subset.
UnclosedGroup
A ( has no matching ).
UnmatchedParen
A ) has no matching (.
UnknownGroup
A group form outside the subset: conditionals (?(...), absent
operators (?~...), callouts, (?P<...>), (?'name'...), and the
like.
UnknownOption
An inline option other than i, m, and x, or an option group with
no options ((?), (?-)).
UnclosedComment
A (?# comment has no closing ).
InvalidGroupName
A group or back-reference name is not an ASCII identifier
([A-Za-z_][A-Za-z0-9_]*).
DuplicateGroupName
Two named groups share a name.
MixedGroups
The pattern has both named groups and plain capturing groups.
Oniguruma numbers plain groups only when told to (VS Code does; other
engines do not), so capture numbers would differ between editors. Use
(?:...) for grouping, or name every group.
NumberedBackrefWithNamedGroups
A numbered back-reference in a pattern with named groups, which
Oniguruma refuses unless plain groups capture. Use \k<name>.
UndefinedGroupName
\k<name> names no group in the pattern.
BackreferenceOutOfRange
A numbered back-reference names a group the pattern does not have.
In an end or while pattern, numbered back-references name groups of
the rule’s begin pattern.
Fields
UnclosedClass
A [ has no matching ].
EmptyClass
A character class, or one side of a && intersection, is empty. ]
is never taken literally at the start of a class: write \].
UnescapedBracket
A ] outside a class. Write \] for the character.
InvalidRange
A range in a class runs backwards (z-a), or a - sits where it
is neither the first or last item nor between two single characters.
Write \- for the character.
UnknownPosixClass
[: inside a class does not start a POSIX bracket from the supported
list ([:alpha:], [:^digit:], …). Write \[: for the characters.
NothingToRepeat
A quantifier with nothing before it to repeat.
RepeatedQuantifier
A quantifier directly after another (a**, a{2}{3}). Oniguruma reads
these as nested repetition, other engines refuse them; group the inner
repetition explicitly.
AmbiguousQuantifier
{n}?, {n}+, or {n,m}+. Oniguruma reads x{n}? as an optional
x{n} and x{n,m}+ as a repeated x{n,m}, where other engines read
lazy and possessive repetition. Group explicitly: (?:x{n})?.
InvalidInterval
A { that does not start a valid {n}, {n,}, or {n,m}
quantifier, a count above 100000, or {n,m} with n > m. Write \{
for the character; write {0,m} for {,m}.
QuantifiedAssertion
A quantifier applied to an anchor or a look-around, which Oniguruma refuses or ignores.
LookbehindNotFixed
A look-behind alternative whose length is not fixed. Each top-level alternative of a look-behind must match a fixed number of characters, and alternatives of groups inside it must all have the same length.
CaptureInLookbehind
A capturing group or a back-reference inside a look-behind.
TooDeep
Groups and classes nest more than MAX_REGEX_DEPTH deep.
NulCharacter
A raw NUL character; engines that read patterns as C strings stop
there. Write \x00.
BackslashBeforeDigit
In an end or while pattern, an escaped backslash followed by a
digit (\\1). VS Code substitutes begin captures into these
patterns by searching the text for a backslash and digits, and would
treat the second backslash as a back-reference. Write \x5c1.
TooManyGroups
More capture groups than fit in a u32.