pub enum Look {
    Start,
    End,
    StartLF,
    EndLF,
    StartCRLF,
    EndCRLF,
    WordAscii,
    WordAsciiNegate,
    WordUnicode,
    WordUnicodeNegate,
}
Expand description

A look-around assertion.

An assertion matches at a position between characters in a haystack. Namely, it does not actually “consume” any input as most parts of a regular expression do. Assertions are a way of stating that some property must be true at a particular point during matching.

For example, (?m)^[a-z]+$ is a pattern that:

  • Scans the haystack for a position at which (?m:^) is satisfied. That occurs at either the beginning of the haystack, or immediately following a \n character.
  • Looks for one or more occurrences of [a-z].
  • Once [a-z]+ has matched as much as it can, an overall match is only reported when [a-z]+ stops just before a \n.

So in this case, abc and \nabc\n match, but \nabc1\n does not.

Assertions are also called “look-around,” “look-behind” and “look-ahead.” Specifically, some assertions are look-behind (like ^), other assertions are look-ahead (like $) and yet other assertions are both look-ahead and look-behind (like \b).

Assertions in an NFA

An assertion in a thompson::NFA can be thought of as a conditional epsilon transition. That is, a matching engine like the PikeVM only permits moving through conditional epsilon transitions when their condition is satisfied at whatever position the PikeVM is currently at in the haystack.

How assertions are handled in a DFA is trickier, since a DFA does not have epsilon transitions at all. In this case, they are compiled into the automaton itself, at the expense of more states than what would be required without an assertion.

Variants§

§

Start

Match the beginning of text. Specifically, this matches at the starting position of the input.

§

End

Match the end of text. Specifically, this matches at the ending position of the input.

§

StartLF

Match the beginning of a line or the beginning of text. Specifically, this matches at the starting position of the input, or at the position immediately following a \n character.

§

EndLF

Match the end of a line or the end of text. Specifically, this matches at the end position of the input, or at the position immediately preceding a \n character.

§

StartCRLF

Match the beginning of a line or the beginning of text. Specifically, this matches at the starting position of the input, or at the position immediately following either a \r or \n character, but never after a \r when a \n follows.

§

EndCRLF

Match the end of a line or the end of text. Specifically, this matches at the end position of the input, or at the position immediately preceding a \r or \n character, but never before a \n when a \r precedes it.

§

WordAscii

Match an ASCII-only word boundary. That is, this matches a position where the left adjacent character and right adjacent character correspond to a word and non-word or a non-word and word character.

§

WordAsciiNegate

Match an ASCII-only negation of a word boundary.

§

WordUnicode

Match a Unicode-aware word boundary. That is, this matches a position where the left adjacent character and right adjacent character correspond to a word and non-word or a non-word and word character.

§

WordUnicodeNegate

Match a Unicode-aware negation of a word boundary.

Implementations§

Flip the look-around assertion to its equivalent for reverse searches. For example, StartLF gets translated to EndLF.

Some assertions, such as WordUnicode, remain the same since they match the same positions regardless of the direction of the search.

Return the underlying representation of this look-around enumeration as an integer. Giving the return value to the Look::from_repr constructor is guaranteed to return the same look-around variant that one started with within a semver compatible release of this crate.

Given the underlying representation of a Look value, return the corresponding Look value if the representation is valid. Otherwise None is returned.

Returns a convenient single codepoint representation of this look-around assertion. Each assertion is guaranteed to be represented by a distinct character.

This is useful for succinctly representing a look-around assertion in human friendly but succinct output intended for a programmer working on regex internals.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.