cryptarchy / regex_generate Goto Github PK
View Code? Open in Web Editor NEWUse regular expressions to generate text.
License: Apache License 2.0
Use regular expressions to generate text.
License: Apache License 2.0
If you create a Generator
with a lower max_repeat
than the pattern requires, the generator will not error, but you will get a panic when actually generating input.
Example input pattern: x{150,}
(repeat x at least 150 times).
panic:
thread <redacted> panicked at 'Uniform::new_inclusive called with `low > high`',<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/distributions/uniform.rs:567:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Regex
(|(20\/([^0179]0|[1234]00|25|125|160|250)|6\/([69]|1[258]|[369]0|[34]8|7\.5|24|75|120)|(1\.0|0\.(0[58]|[12458]0|067|67|16|125|25|33))))
is supported both by Regex crate and Qt, but this crate throws error
could not parse expression
```
Test crate
```
use rand::Rng;
use regex::Regex;
const LIMIT : usize = 1000;
fn main() {
let mut rng = rand::thread_rng();
let re = r"(|(20\/([^0179]0|[1234]00|25|125|160|250)|6\/([69]|1[258]|[369]0|[34]8|7\.5|24|75|120)|(1\.0|0\.(0[58]|[12458]0|067|67|16|125|25|33))))";
let tt = Regex::new(re).unwrap();
dbg!(tt);
let mut generator = regex_generate::Generator::new(&re, &mut rng, 1000).unwrap();
for _ in 0..LIMIT {
let mut buffer : Vec<u8> = Vec::new();
generator.generate(&mut buffer).unwrap();
println!("{}", String::from_utf8(buffer).unwrap());
}
}
```
Hi,
I'm trying to implement the example given in the ReadMe. However, I cannot use rand::thread_rng() as I get the following error:
the trait bound `ThreadRng: rand_core::RngCore` is not satisfied
required because of the requirements on the impl of `rand::Rng` for `ThreadRng`
I first used rand version 0.8.3 and then went back to 0.8 to have the same version as in the example. I also use regex_generate version 0.2 and run the rust compiler stable version 1.49.0.
This is my code (basically the same as the example with a different regex and max repeat):
extern crate regex_generate;
extern crate rand;
use regex_generate::Generator;
fn main() {
let mut gen = Generator::new(r"(a|b|c)*", rand::thread_rng(), 3).unwrap();
let mut buffer = vec![];
gen.generate(&mut buffer).unwrap();
let output = String::from_utf8(buffer).unwrap();
println!("Random Date: {}", output);
}
I hope you can somehow reproduce this problem.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.