var myString = "abcdefghijklmnopqrstuvwxyz";
var firstString = myString.substr(0, myString.length - 5);
maskString = firstString.replace(/[a-zA-Z0-9]/g, '*');
var lastString = myString.substr(myString.length - 5);
var newString = maskString.concat(lastString);
document.write("1st: " + firstString);
document.write("<br/>");
document.write("2nd: " + lastString);
document.write("<br/>");
document.write("3rd: " + newString);

Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.