in reply to Re: Replace the last letter
in thread Replace the last letter
The main version does the right thing, but the alternative doesn't - negative lookahead will look for something immediately following, so:
means "find the letter, not followed by the letter again, but followed by the end anchor". I think you want instead:$variable =~ s/$tofind(?![$tofind])$/$replacement/;
ie "find the letter, not followed by (zero or more characters and) the letter again".$variable =~ s/$tofind(?!.*$tofind)/$replacement/;
Also, the [$tofind] character class is the same as $tofind itself when it refers to a single letter, but doesn't do the right thing if $tofind is something more complex.
Hugo
|
|---|