I am trying to mask email address in the following different ways.
Mask all characters except first three and the ones follows the @ symbol. This expression works fine.
(?<=.{3}).(?=[^@]*?@)
abcdefgh@gmail.com -> abc*****@gmail.com
Mask all characters except last three before @ symbol.
Example : abcdefgh@gmail.com -> *****fgh@gmail.com
I am not sure how to check for @ and do reverse match.
Can someone throw pointers on this?
Advertisement
Answer
Maybe you could do a positive lookahead:
.(?=.*...@)
See the online Demo
.
– Any character other than newline.(?=.*...@)
– Positive lookahead for zero or more characters other than newline followed by three characters other than newline and@
.