Skip to main content

RegexErrorKind

Enum RegexErrorKind 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§group: u32

The group the back-reference names.

§groups: u32

How many capture groups there are to refer to.

§

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.

Trait Implementations§

Source§

impl Clone for RegexErrorKind

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RegexErrorKind

Source§

impl Debug for RegexErrorKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RegexErrorKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RegexErrorKind

Source§

impl PartialEq for RegexErrorKind

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RegexErrorKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.