in reply to Case-preserving regexp search and replace?
$_ = "this is a TEsT case"; s/(test)/preserve_case($1, "success")/egi; sub preserve_case { my ($from, $to) = @_; my ($lf, $lt) = map length, @_; if ($lt < $lf) { $from = substr $from, 0, $lt } else { $from .= substr $to, $lf } return uc $to | ($from ^ uc $from); }
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Case-preserving regexp search and replace?
by rrwo (Friar) on Aug 31, 2001 at 08:33 UTC | |
by japhy (Canon) on Aug 31, 2001 at 09:26 UTC |