[−][src]Crate rec
Regular Expression Constructor - the recreational version of regular expressions
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:
- WYSIWYG: [
&str] andcharare interpreted exactly as written (i.e. no metacharacters); all metacharacters (as well as other useful patterns) are provided by theClassstruct. - Simple to understand quantifier and capture group syntaxes.
- Uses operators to provide easy to understand expressions.
Patternexpands onRegexAPI to simplify access to data.
This library utilizes the regex crate.
Getting Started
Add the following to your Cargo.toml:
[dependencies]
rec = "0.10.0"
Examples
Use Regex API.
A Pattern is a smart pointer to a Regex, so one can call the same functions.
use rec::{some, Class, Pattern}; let pattern = Pattern::new("hello" + some(Class::Whitespace) + (Class::Digit | "world")); assert!(pattern.is_match("hello world"));
Use Pattern to capture a group.
Pattern additionally provides helper functions to reduce boilerplate.
use rec::{prelude::*, some, tkn, var, Class, Pattern}; let decimal_number = Pattern::new(tkn!("whole" => some(Class::Digit)) + "." + var(Class::Digit)); assert_eq!(decimal_number.name_str("23.2", "whole"), Some("23"));
FAQ
I know regular expression syntax; why should I use 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.
Modules
| prelude | Common traits and structs used throughout |
Macros
| tkn | Creates a |
Structs
| Match | Match represents a single match of a regex in a haystack. |
| Pattern | Represents a regular expression to be matched against a target. |
| Regex | A compiled regular expression for matching Unicode strings. |
| Tokens | Stores the found capture groups. |
Enums
| Ch | Represents a match of one character. |
| Class | An enumeration of predefined single character matches. |
Functions
| btwn | Returns a |
| exact | Returns a |
| lazy_btwn | Returns a |
| lazy_max | Returns a |
| lazy_min | Returns a |
| lazy_opt | Returns a |
| lazy_some | Returns a |
| lazy_var | Returns a |
| max | Returns a |
| min | Returns a |
| opt | Returns a |
| some | Returns a |
| var | Returns a |