in reply to Brute Force Algorithm with Perl reg exprs?
Occasionally, most of us would like to have an operation which generates a matching string from a regex. There is no such thing in perl (or elsewhere, afaik).
You want a list of all qualified strings which contain a given substring. One way is to generate all the "free" strings that qualify and insert the known substring into each possible location.
I've simplified the problem to numerals-only to make it easy to generate the free list. Extending to lowercase characters is up to you. Then all you need to do is find the one you wanted from @brute_list ;-)my $len = 6; my $hint = q(1234); my $free = $len - length $hint; my @brute_list; for my $seed ( '0'x$free .. '9'x$free ) { for ( 0 .. $free ) { my $string = $seed; substr( $string, $_, 0) = $hint; push @brute_list, $string; } } print "@{brute_list}$/";
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Brute Force Algorithm with Perl reg exprs?
by QM (Parson) on Apr 25, 2006 at 03:28 UTC |