我正在构建 SMS 网关,如果 SMS 消息在将其保存到数据库之前有任何凭据信息(例如密码),我想在其中屏蔽它。
这是代码:
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);
我对正则表达式的了解很差,所以如果可能的话,我需要你的帮助才能获得以下输出:
bMasked: true
plainText: Your password is 1234!
withStars: Your password is ****!