http://qs321.pair.com?node_id=643000


in reply to Re^2: searching for a string w/ a * in any single position?
in thread searching for a string w/ a * in any single position?

Generalizing this approach for Hamming distance > 1, using the combinations iterator from Iterating over combinations:
sub gen_regex { my ($target, $n) = @_; my @chars = split //, $target; my $ra = Regexp::Assemble->new(); my $iter = combinations( $n => [ 0 .. $#chars ] ); while (my @c = $iter->()) { local @_ = @chars; $_[$_] = '.' for @c; $ra->add( join '', @_ ); } $ra->re(); }

blokhead