Re: regex replace credit card numbers with *



Paul Lalli <mritty@xxxxxxxxx> wrote:
>
> A. Sinan Unur wrote:
>> "cldmismgr" <admin@xxxxxxxxxx> wrote in news:1128001319.174650.190970
>> @g47g2000cwa.googlegroups.com:
>>
>> > replace all but the last 4 numbers
>> > in a credit card number with *'s.


>> my $cc = '123456789012345';
>> $cc =~ tr/0123456789/*/;

> Er, the output of that code is a series of 15 *'s. Doesn't seem to be
> what the OP asked for.


So let's fix it with an lvalue substr():

substr($cc, 0, -4) =~ tr/0-9/*/;


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.



Relevant Pages