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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Generate random strings from regular expression
by tybalt89 (Monsignor) on Jul 02, 2024 at 21:00 UTC | |
by bliako (Abbot) on Jul 05, 2024 at 10:52 UTC | |
Re: Generate random strings from regular expression
by LanX (Saint) on Jul 02, 2024 at 13:54 UTC | |
Re: Generate random strings from regular expression
by NERDVANA (Priest) on Jul 06, 2024 at 00:44 UTC | |
by bliako (Abbot) on Jul 08, 2024 at 08:53 UTC | |
by NERDVANA (Priest) on Jul 08, 2024 at 09:10 UTC | |
Re: Generate random strings from regular expression
by cavac (Prior) on Jul 05, 2024 at 12:04 UTC |