partially mask a email address – javascript

You could seach for a group of four characters and replace a group of two until you found an @ sign-

const
    mask = string => string.replace(
        /(..)(.{1,2})(?=.*@)/g,
        (_, a, b) => a + '*'.repeat(b.length)
    );

console.log(mask('[email protected]'));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top