Crate rec

source ·
Expand description

Regular Expression Constructor.

Makes the process of constructing regular expressions easier to accomplish and understand by implementing the following functionality:

  • WYSIWYG: &str is interpreted exactly as written (i.e. no metacharacters); all metacharacters are provided via the ChCls enum.
  • Simple to understand quantifier syntax and capture name syntax.
  • Overloads operators to provide easy to understand expressions.
  • Pattern returns exactly what is requested to reduce boilerplate.

Utilizes the regex crate.

Examples

Create a Regex

You can use Rec to construct a Regex.

use rec::{Atom, ChCls, SOME};

let a_rec = "hello" + ChCls::WhSpc.rpt(SOME) + (ChCls::Digit | "world");
let regex = a_rec.build();

assert!(regex.is_match("hello    world"));

Use Pattern to tokenize

Instead of using Regex, you can use Pattern to handle basic matching needs.

use rec::{Atom, ChCls, VAR, SOME, Pattern};

let decimal_number = Pattern::define(ChCls::Digit.rpt(SOME).name("whole") + "." + ChCls::Digit.rpt(VAR));

assert_eq!(decimal_number.tokenize("23.2").get("whole"), Some("23"));

Structs

Represents a regular expression to be matched against a target.
Constructs a regular expression.
Stores the possible matches of a Pattern against a target.
Iterates through a given target returning each Tokens found.

Enums

Specifies a set of characters to be matched against.

Constants

Quantifier that repeats an element zero or one times.
Quantifier that repeats an element one or more times.
Quantifier that repeats an element zero or more times.

Traits

Specifies the characters to be matched against.
Specifies how often an element may be repeated.

Type Definitions

A Quantifier that is defined before runtime.