0

I want to mask email address like below.

Input: test@gmail.com; helloworld@yahoo.co.in; ibibo@hotmail.com;

Output: ts@gmail.com; hw@yahoo.co.in; i*i**@hotmail.com;

Below Regex is excluding domain part but masking all characters in first part, except first character.

input.replaceAll("(?<=.{1}).(?=[^@]*?@)","X");

like helloworld@yahoo.co.in to hxxxxxxxxx@yahoo.co.in

I wanted to print a character in middle of the local-part like hxxxxWxxxx@yahoo.co.in

FYI -

I want to get first and middle character (random middle character in case of even length(4/6/8 characters).

Like below.

Alpha@gmail.com -> A & p characters

Beta@gmail.com --> B & t

Kat@yahoo.com -> k&a or k&t

sheshadri
  • 23
  • 5
  • The "hard part" of what you're looking for is [How to match the middle character in a string with regex?](https://stackoverflow.com/q/28051651/11107541) – starball May 03 '23 at 05:52
  • 2
    Also, I don't understand your example "_Kat@yahoo.com -> k&a or k&t_" why "k&t"? The middle character of the username there is pretty unambiguously "a". And why is your "_Beta@gmail.com --> B & t_" not instead "B&t or B&e"? – starball May 03 '23 at 05:53

0 Answers0