0

I want to mask email address like below.

Input: [email protected]; [email protected]; [email protected];

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 [email protected] to [email protected]

I wanted to print a character in middle of the local-part like [email protected]

FYI -

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

Like below.

[email protected] -> A & p characters

[email protected] --> B & t

[email protected] -> 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 "[email protected] -> k&a or k&t_" why "k&t"? The middle character of the username there is pretty unambiguously "a". And why is your "[email protected] --> B & t_" not instead "B&t or B&e"? – starball May 03 '23 at 05:53

0 Answers0