Expand description
The regen crate provides a library and an command-line tool for generating all strings matching a regular expression.
§Generator construction
The Generator struct is the basic abstraction of
the regen
crate. Use the
Generator::new method to create a
generator with default options.
use regen::Generator;
let mut gen = Generator::new("[a-z]{2}")?;
Use the Generator::new_with_options method to create a generator with user defined option values provided in the GeneratorOptions struct.
use regen::{Generator, GeneratorOptions};
let opts = GeneratorOptions{max_length: 7};
let mut gen = Generator::new_with_options("[a-z]*", &opts)?;
§String generation matching a regex
Use the Generator::append_next
method to append the next generated string to an existing Vec<u8>
.
use regen::Generator;
let mut out = Vec::new();
let mut gen = Generator::new("[a-z]{2}")?;
while gen.append_next(&mut out).is_some() {
// Process 'out'...
// and possibly out.clear() depending on the scenario.
}
For a more straightforward, but possibly less efficient way to generate
strings, the Generator struct also implements the
std::iter::Iterator
trait.
use regen::Generator;
let mut gen = Generator::new("[a-z]{2}")?;
for out in gen {
// Process 'out'...
}
Structs§
- Generator
- A generator for strings matching a regular expression
- Generator
Options - The options with which to create a
Generator
.