how can ı mask an e-mail with regex for java like this
foo@bar.com
f*o@b*****m
ı used this
String maskedEmail = email.replaceAll("(?<=.{1}).(?=[^@]*?.@)", "*");
but ı get this: f*o@bar.com
my problem:ı cant control after @
ı want to control it like before @ at the same time.
ıt is important for banned words without e-mail verification
Asked
Active
Viewed 51 times
0

mtgosling
- 1
- 1
- 1
-
Adjusting my former solution, you may use [`replaceAll("(?<=.)[^@](?=[^@]*[^@]@)|(?:(?<=@.)|(?!^)\\G(?=[^@]*$)).(?!$)", "*")`](https://regex101.com/r/qg72Rm/2) – Wiktor Stribiżew Jun 28 '18 at 08:10
-
1@SilvanBregy That is validation, here, OP wants to *mask*. – Wiktor Stribiżew Jun 28 '18 at 08:13
-
@WiktorStribiżew Next time I read the question a bit more precisely. – Silvan Bregy Jun 28 '18 at 08:55