I am building SMS gateway where I want to mask any credential info (e.g. password) if the SMS message has any before persisting it into the database.
Here is the code:
String message = "Your password is [MASK:1234]!";
boolean bMasked = message.matches("(\\[MASK:)*(\\])");
String plainText = message.replaceAll(..., "");
String withStars = message.replaceAll("...", "*");
System.out.println("bMasked: " + bMasked);
System.out.println("plainText: " + plainText);
System.out.println("withStars: " + withStar);
My knowledge in the regular expression is poor, so I need your help if possible to get the following output:
bMasked: true
plainText: Your password is 1234!
withStars: Your password is ****!