I needed to generate random strings from a regular expression and I have found (*) a C++ library (regxstring C++ library by daidodo) which does just that and works fine for my use case. It claims that it supports most Perl 5 regexp syntax. It is quite fast too. So I have ported it into a Perl module, here : String::Random::Regexp::regxstring.
perl -MString::Random::Regexp::regxstring -e 'print @{generate_random_ +strings(q{^\d{3}[-,.][A-V][a-z]{3}\d{2}})};'
use String::Random::Regexp::regxstring; my $strings = generate_random_strings('^[a-c]{2}[-,.]\d{3}-[A-Z]{2}$', + 10); print "@$strings\n"
The XS and C++ code bridging Perl to C++ library are very simple and can serve as an example for doing that for other libraries. Go forth and multiply.
(*) Via this old thread I found Regexp::Genex and there is also String::Random. Neither worked for my use case.
bw, bliako
In reply to Generate random strings from regular expression by bliako
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |