in reply to Re: searching for a string w/ a * in any single position?
in thread searching for a string w/ a * in any single position?
I think the following will do the trick:
my @chars = map quotemeta, split //, $word; my $re = join '|', map { local @_ = @chars; $_[$_] = '.'; join '', @_ } 0..$#chars;
Using Regexp::Assemble should be faster:
use Regexp::Assemble qw( ); my @chars = map quotemeta, split //, $word; my $ra = Regexp::Assemble->new(); for (0..$#chars) { local @_ = @chars; $_[$_] = '.'; $ra->add(join '', @_) } my $re = $ra->re();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: searching for a string w/ a * in any single position?
by blokhead (Monsignor) on Oct 05, 2007 at 23:06 UTC |