Skip to main content

Crate re_parser

Crate re_parser 

Source
Expand description

§re-parser

A library for parsing regular expression patterns into an abstract syntax tree (AST).

§Supported syntax

SyntaxDescription
aLiteral character
.Any character (except newline)
^ $Start / end of string anchors
\b \BWord / non-word boundary
\d \D \w \W \s \SPredefined character classes
[abc] [^abc] [a-z]Character classes
(...)Capturing group
(?P<name>...)Named capturing group
(?:...)Non-capturing group
(?=...) (?!...)Positive / negative lookahead
(?<=...) (?<!...)Positive / negative lookbehind
* + ?Greedy quantifiers
*? +? ??Lazy quantifiers
{n} {n,} {n,m}Counted quantifiers
a|bAlternation
\n \t \rCommon escape sequences

§Example

use re_parser::parse;
use re_parser::ast::{Regex, QuantKind};

let ast = parse(r"\d+").unwrap();
// Regex::Quantifier(Box::new(Regex::EscapeClass(EscapeClass::Digit)), QuantKind::OneOrMore, true)
println!("{ast:#?}");

Re-exports§

pub use width::Width;

Modules§

ast
error
width
The Width type and the node_width convenience constructor.

Functions§

parse
Parse a regex pattern string into an ast::Regex AST.
pattern_width
Parse pattern and return the minimum and maximum number of characters it can match.