You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generates random strings and byte strings matching a regex.
Examples
use rand::{SeedableRng,Rng};letmut rng = rand_xorshift::XorShiftRng::from_seed(*b"The initial seed");// creates a generator for sampling stringslet gen = rand_regex::Regex::compile(r"\d{4}-\d{2}-\d{2}",100).unwrap();// sample a few strings randomlylet samples = (&mut rng).sample_iter(&gen).take(3).collect::<Vec<String>>();// all Unicode characters are included when samplingassert_eq!(samples, vec!["꧰᪈৭᱃-𐒧᧒-௦۴".to_string(),"𞓰۳꩑-᪄9-໔᮹".to_string(),"𑛃𑃹९೭-١᥈-৫೪".to_string()]);// you could use `regex_syntax::Hir` to include more optionsletmut parser = regex_syntax::ParserBuilder::new().unicode(false).build();let hir = parser.parse(r"\d{4}-\d{2}-\d{2}").unwrap();let gen = rand_regex::Regex::with_hir(hir,100).unwrap();let samples = (&mut rng).sample_iter(&gen).take(3).collect::<Vec<String>>();assert_eq!(samples, vec!["2839-82-12".to_string(),"2857-86-63".to_string(),"0381-04-99".to_string(),]);