RustVerbalExpressions
This crate provides a Rust implementation of VerbalExpressions in order to build regex
strings without knowing the minutiae of regex syntax.
It uses the regex
crate to compile the created regex strings.
Versions are numbered according to semver.
Usage
Add this to your Cargo.toml:
[dependencies]
verex = "0.2"
and this to your crate root:
extern crate verex;
Examples
A simple example to show the usage:
extern crate verex;
use verex::Verex;
use verex::find;
fn main() {
let mut verex = Verex::new();
let regex1 = verex.find("a")
.compile()
.unwrap();
let regex2 = verex.or_find("b")
.compile()
.unwrap();
let regex3 = find("a") .or_find("b")
.compile()
.unwrap();
assert!(!regex1.is_match("b"));
assert!(regex2.is_match("b"));
assert!(regex3.is_match("b"));
}
Here's a URL testing example shamelessly stolen from the python Verex readme:
extern crate verex;
use verex::start_of_line;
fn main() {
let verex = start_of_line()
.find("http")
.maybe("s")
.find("://")
.maybe("www.")
.anything_but(" ")
.end_of_line();
let regex = verex.compile().unwrap();
let test_url = r"https://www.google.com";
assert!(regex.is_match(test_url));
assert_eq!(verex.source(), r"(?:^(?:http)(?:s)?(?:://)(?:www\.)?(?:[^ ]*)$)");
}