The following module was proposed for inclusion in the Module List:
modid: Regexp::Genex
DSLIP: cdpfp
description: Get strings matching a regex, using a regex
userid: BOWMANBS (Brad Bowman)
chapterid: 11 (String_Lang_Text_Proc)
communities:
Idea & prior art search at perlmonks nodes: 284513 286981
similar:
String::Random
rationale:
I'm have a prelimiary version working which I'll upload soonish.
The basic idea is on the perlmonks link, although I'm using
YAPE::Regex to automate it.
Naming ------------------------------------------ Regexp::Genex
because the module is more focussed on the regex than the resulting
strings. Genex is the name I started using. (Admittedly, I like the
Reality Bites connotations)
I prefer it to Regexp::Generator because that sounds like what
Regexp::List & Regexp::PreSuf are doing. There's also
Regex::Generate in parrot.
I want to avoid these false associations but am open to better
ideas.
Synposis ------------------------------------------ This stuff is
going more or less:
use Regexp::Genex qw(strings regex rx_string count);
my $rx = shift || '^a(b|c)d{2,3}$' || qr/^ reg(ular\s?)?
ex(p)?(ression)? $/x;
print "'", join("', '", strings($rx)), "'\n"; # 'abddd', 'abdd',
'acddd', 'acdd'
my $target = 'a' x 2; # limits total quantifiers, greed is search
order print "got '$_'\n" for( $target =~ regex('^a(b|c)d*?$'); #
'ab', 'abd', 'abdd', 'abddd', 'ac', 'acd', 'acdd', 'acddd' do {
print 'len ',length($target),' => count ',count($rx); } while (
$target += 'a' x 3 ); # len 3 => count 8, len 6 => count 14, len 9
=> 20 # count = 2 * (len + 1)
print rx_string($rx); # 'aaaaaaaaa' =~ /(?x-ims: # ^(?> (?{ @_ =
(); '' }) ) # Initialize $^R & @_ # (?: (?{ $^R.'a' }) ) # a # ( #
(?: (?{ $^R.'b' }) ) # b # |(?: (?{ $^R.'c' }) ) # c # ) # (?: . (?{
$^R.'d' }) ){0,20}? # d*? # # (?{ push @_, $^R }) (?!) # Save &
backtrack # ) # /x;
Utility ------------------------------------------- Test and debug
your regex. Generate test data. Generate combinations. Generate data
according to a lexical pattern (urls, etc) Edit the regex code to do
different things (eg. limit it) Analyse someone else's qr// object.
Use the strings to create a DFA :)
Unlike String::Random, the strings aren't random :) they're what
the regex engine would look for. They're ordered and exhaustive to
the limit of target string size.
I also plan to do something sensible to other regex elements. eg.
non-anchored has implicit .* at start and end, '.', \d, [a-d]
produce random matches (exhaustive to much),
enteredby: BOWMANBS (Brad Bowman)
enteredon: Sat Sep 13 10:08:48 2003 GMT
The resulting entry would be:
Regexp::
::Genex cdpfp Get strings matching a regex, using a regex BOWMANBS
Thanks for registering,
--
The PAUSE
PS: The following links are only valid for module list maintainers:
Registration form with editing capabilities:
https://pause.perl.org/pause/authenquery?ACTION=add_mod&USERID=ab400000_65be145aa1ab4093&SUBMIT_pause99_add_mod_preview=1
Immediate (one click) registration:
https://pause.perl.org/pause/authenquery?ACTION=add_mod&USERID=ab400000_65be145aa1ab4093&SUBMIT_pause99_add_mod_insertit=1