in reply to Re: Matching a truncated word
in thread Matching a truncated word
The format of the regex is something like:sub trunc_match { my ($what) = @_; my @bits; for (1..length $what) { push (@bits,$what); chop $what; } return '('.join ('|', map { quotemeta($_) } @bits).')$'; } my $rx = trunc_match ("foobar"); $_ = "This sentence ends in foob"; if (/$rx/) { print "Truncated, ends in '$1'\n"; }
(foobar|fooba|foob|foo|fo|f)$So you get whatever you're looking for in $1, or the returned array if you're brave enough to use /g.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: Matching a truncated word
by John M. Dlugosz (Monsignor) on Aug 01, 2001 at 01:33 UTC |