Regular Expression Constructor - making regular expressions fun
rec
is a Rust library that simplifies the process of writing, reading, and using regular
expressions. This library is intended for all users working with regular expressions, no matter
their familiarity with regular expression syntax. Below is a summary of the functionality
provided by rec
:
ChCls
] enum.Pattern
] returns exactly what is requested to reduce boilerplate.This library utilizes the [regex
] crate.
Add the following to your Cargo.toml
:
rust
[dependencies]
rec = "0.3"
If you prefer API of [regex
], you can use a [Rec
] to construct a [Regex
].
```rust
use rec::{some};
use rec::ChCls::{Digit, Whitespace};
let arec = "hello" + some(Whitespace) + (Digit | "world"); let regex = arec.build();
assert!(regex.is_match("hello world")); ```
Instead of using [Regex
], you can use [Pattern
] to handle basic matching needs.
```rust
use rec::{some, tkn, var, Element, Pattern};
use rec::ChCls::Digit;
let decimal_number = Pattern::new(tkn!(some(Digit) => "whole") + "." + var(Digit));
asserteq!(decimalnumber.tokenize("23.2").get("whole"), Some("23")); ```
rec
?In order for code to be easily maintainable, it should be as simple as possible. Even if the original developer understands their regular expression, it is beneficial for the project as a whole if all contributors are able to easily understand the function of a regular expression.
License: MIT