Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expressions, credit card numbs..

Status
Not open for further replies.

VeryFrustrated

Programmer
Jun 21, 2002
7
GB
How do you replace every digit in a credit card number with 'X'
leaving the last four digits intact using regular expressions.

example: XXXXXXXXX3567

Thanks in advance...
 
Here's two different ways to do it:

$String = '1234567890123456';
$String =~ s/.(?=.{4})/X/g;
print "$String\n";

$str = '1234567890123456';
substr($str,0,(length($str)-4)) = ('X' x (length($str)-4));
print "$str\n";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top