Crates.io | regex_generate |
lib.rs | regex_generate |
version | 0.2.3 |
source | src |
created_at | 2017-05-30 03:32:42.259649 |
updated_at | 2023-03-07 20:51:21.955548 |
description | Use regular expressions to generate text. |
homepage | https://github.com/CryptArchy/regex_generate |
repository | https://github.com/CryptArchy/regex_generate |
max_upload_size | |
id | 16858 |
size | 36,128 |
Use regular expressions to generate text. This crate is very new and raw. It's a work-in-progress, but feel free to add issues or PRs or use it for your own ideas, if you find it interesting. No guarantees or warranties are implied, use this code at your own risk.
Thanks to the amazing folks who work on rust-lang/regex which is the heart of this crate. Using regex_syntax made this crate 1000x easier to produce.
Magically generated and graciously hosted by Docs.rs.
The documentation is not good right now.
Add this to your Cargo.toml
:
[dependencies]
regex_generate = "0.2"
and this to your crate root:
extern crate regex_generate;
This example generates a date in YYYY-MM-DD format and prints it. Adapted from the example for rust-lang/regex.
extern crate regex_generate;
extern crate rand;
use regex_generate::{DEFAULT_MAX_REPEAT, Generator};
fn main() {
let mut gen = Generator::new(r"(?x)
(?P<year>[0-9]{4}) # the year
-
(?P<month>[0-9]{2}) # the month
-
(?P<day>[0-9]{2}) # the day
", rand::thread_rng(), DEFAULT_MAX_REPEAT).unwrap();
let mut buffer = vec![];
gen.generate(&mut buffer).unwrap();
let output = String::from_utf8(buffer).unwrap();
println!("Random Date: {}", output);
}
Run tests with cargo test -- --nocapture
Run benchmarks with rustup run nightly cargo bench
.
really means any, as in any valid unicode character.\d
means any number, not just [0-9]
..*
) is 100, but you can set it yourself with generate_with_max_repeat
.Literal
regex_generate is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
See LICENSE-APACHE and LICENSE-MIT for details.