Currently i am using the logback framework and patterns in my logs , but I need to mask the PII information for email-id. I need The regular expression which helps to Mask my email Address from the logs, my requirement was to mask only 30% of the email id. Since i am using the Logback we can use the logback and masking pattern
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<maskPattern>(?<=.{3}).(?=[^@]*?@)</maskPattern> <!--mask email-->
</encoder>
</appender>
For example : testing@test.com
Expected Result:tes***@test.com
I tried Using Different Regular expressions from google and none of them works with the logback framework. For example when i use the below regular expression in logback.xml was not able to parse it or compile it. i have taken reference as : https://howtodoinjava.com/logback/masking-sensitive-data/
<maskPattern><![CDATA[/(?<=.{3}).(?=[^@]*?@)]]></maskPattern>
<maskPattern><(?<=.{3}).(?=[^@]*?@)></maskPattern>
Examples: Can any body please provide me the correct regular expression or pattern, below are the regular expression or pattern i tried none of them works.
1) (?<=.{3}).(?=.*@)
2) (?<=.{2}).(?=[^@]*?@)
3) ([^@]{4})[^@]*(.+)
4) \\b(\\w)[^@]+@\\S+(\\.[^\\s.]+)
please check the screen shot below. enter image description here
ref: https://stackoverflow.com/questions/33100298/masking-of-email-address-in-java