Expand description
§re-parser
A library for parsing regular expression patterns into an abstract syntax tree (AST).
§Supported syntax
| Syntax | Description |
|---|---|
a | Literal character |
. | Any character (except newline) |
^ $ | Start / end of string anchors |
\b \B | Word / non-word boundary |
\d \D \w \W \s \S | Predefined 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|b | Alternation |
\n \t \r | Common 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
Widthtype and thenode_widthconvenience constructor.
Functions§
- parse
- Parse a regex pattern string into an
ast::RegexAST. - pattern_
width - Parse
patternand return the minimum and maximum number of characters it can match.