I know you can generate all permutations from a list, using glob or Algorithm::Permute for example - but how do you generate all possible permutations from a regular expression?
I want to do like:
@perms = permute( "/\s[A-Z][0-9][0-9]/" );
sub permute( $regex ) {
# code - put all permutations of above regex in a list
return @list;
}
See Section 6.5 (PDF) in Higher Order Perl. Consider buying the print book: It is a work of art.
There is also Regexp::Genex on CPAN.
Any possibly implementation should have a reasonable maximum length in mind for the generated strings.
If there's a +
or *
anywhere in that regexp, the possibilities could be without end.
Regexp::Genex considers this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With