Enum fancy_regex::Expr
source · [−]pub enum Expr {
Show 18 variants
Empty,
Any {
newline: bool,
},
StartText,
EndText,
StartLine,
EndLine,
Literal {
val: String,
casei: bool,
},
Concat(Vec<Expr>),
Alt(Vec<Expr>),
Group(Box<Expr>),
LookAround(Box<Expr>, LookAround),
Repeat {
child: Box<Expr>,
lo: usize,
hi: usize,
greedy: bool,
},
Delegate {
inner: String,
size: usize,
casei: bool,
},
Backref(usize),
NamedBackref(String),
AtomicGroup(Box<Expr>),
KeepOut,
ContinueFromPreviousMatchEnd,
}
Expand description
Regular expression AST. This is public for now but may change.
Variants
Empty
An empty expression, e.g. the last branch in (a|b|)
Any
Fields
newline: bool
Whether it also matches newlines or not
Any character, regex .
StartText
Start of input text
EndText
End of input text
StartLine
Start of a line
EndLine
End of a line
Literal
The string as a literal, e.g. a
Concat(Vec<Expr>)
Concatenation of multiple expressions, must match in order, e.g. a.
is a concatenation of
the literal a
and .
for any character
Alt(Vec<Expr>)
Alternative of multiple expressions, one of them must match, e.g. a|b
is an alternative
where either the literal a
or b
must match
Group(Box<Expr>)
Capturing group of expression, e.g. (a.)
matches a
and any character and “captures”
(remembers) the match
LookAround(Box<Expr>, LookAround)
Look-around (e.g. positive/negative look-ahead or look-behind) with an expression, e.g.
(?=a)
means the next character must be a
(but the match is not consumed)
Repeat
Fields
lo: usize
The minimum number of repetitions
hi: usize
The maximum number of repetitions (or usize::MAX
)
greedy: bool
Greedy means as much as possible is matched, e.g. .*b
would match all of abab
.
Non-greedy means as little as possible, e.g. .*?b
would match only ab
in abab
.
Repeat of an expression, e.g. a*
or a+
or a{1,3}
Delegate
Fields
inner: String
The regex
size: usize
How many characters the regex matches
casei: bool
Whether the matching is case-insensitive or not
Delegate a regex to the regex crate. This is used as a simplification so that we don’t have to represent all the expressions in the AST, e.g. character classes.
Backref(usize)
Back reference to a capture group, e.g. \1
in (abc|def)\1
references the captured group
and the whole regex matches either abcabc
or defdef
.
NamedBackref(String)
Back reference to a named capture group.
AtomicGroup(Box<Expr>)
Atomic non-capturing group, e.g. (?>ab|a)
in text that contains ab
will match ab
and
never backtrack and try a
, even if matching fails after the atomic group.
KeepOut
Keep matched text so far out of overall match
ContinueFromPreviousMatchEnd
Anchor to match at the position where the previous match ended
Implementations
Trait Implementations
impl Eq for Expr
impl StructuralEq for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnwindSafe for Expr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more