[eluser]TheFuzzy0ne[/eluser]
Code:
$card_number = '1234-5678-9101-1121';
$card_number = 'xxxx-xxxx-xxxx-' . substr($cardnumber, 15);
Untested, but should work as expected. As credit card numbers are in a standard format, you don't need any regexes. That's just overkill. Instead, grab the part of the number you want, and append it to the mask.