[][src]Crate rec

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 (as well as some other useful patterns) 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

If you prefer API of regex, you can use a Rec to construct a Regex.

use rec::{some};
use rec::ChCls::{Digit, Whitespace};

let a_rec = "hello" + some(Whitespace) + (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::{some, tkn, var, Element, Pattern};
use rec::ChCls::Digit;

let decimal_number = Pattern::define(tkn!(some(Digit) => "whole") + "." + var(Digit));

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

Macros

tkn

Creates a capture group with a given name.

Structs

Location

Represents where in the target that a match was found.

Locations

Iterates through a target, returning the Location of each match.

Pattern

Represents a regular expression to be matched against a target.

Rec

Constructs a regular expression.

Tokens

Stores the possible matches of a Pattern against a target.

TokensIter

Iterates through a given target returning each Tokens found.

Enums

ChCls

Specifies a set of characters to be matched against.

Traits

Element

Signifies elements that can be converted into a Rec.

Functions

btwn

Returns a Rec representing the given [Atom] repeated between 2 numbers.

exact

Returns a Rec representing the given [Atom] repeated a given number of times.

lazy_btwn

Returns a Rec representing the given [Atom] lazily repeated between 2 numbers.

lazy_min

Returns a Rec representing the given [Atom] lazily repeated at least a given number of times.

lazy_opt

Returns a Rec representing a lazy 0 or 1 repeat of [Atom].

lazy_some

Returns a Rec representing the given [Atom] lazily repeated 0 or more times.

lazy_var

Returns a Rec representing a lazy variable number of the given [Atom].

min

Returns a Rec representing the given [Atom] repeated at least a given number of times.

opt

Returns a Rec representing the given [Atom] 0 or 1 times.

some

Returns a Rec representing the given [Atom] repeated 0 or more times.

var

Returns a Rec representing a variable number of the given [Atom].