I want to mask the email id as follows :
Input | Output
qwerty@gmail.com : qw**ty@gmail.com
helloworld@gmail.com : he******ld@gmail.com
stackoverflow@gmail.com : st*********ow@gmail.com
abcde@gmail.com : ab*de@gmail.com
abcd@gmail.com : a**d@gmail.com
abc@gmail.com : a*c@gmail.com
ab@gmail.com : a*@gmail.com
Max 2 characters at both the extremes if available, minimum 1 character at each end are to be displayed or just mask the last character.
The string has to be atleast 2 characters in length (ab@gmail.com).
I referred some of the solutions provided, but was not able to achieve the second and third scenario using those. Is there a possibility to find a fix ? I'm not well versed with regex, so I'm not sure which way to go ahead.
references : masking of email address in java
How to i mask all string characters except for the last 4 characters in Java using parameters?