๋ฐ์ํ
์ด๋ฆ์ asterisk(*)๋ก ์ํธํํ๋ ์ฝ๋์ ๋๋ค.
/**
* maskingName
*
* @param str
* @return String
*/
public static String maskingName(String str) {
String replaceString = str;
String pattern = "";
if(str.length() == 2) {
pattern = "^(.)(.+)$";
} else {
pattern = "^(.)(.+)(.)$";
}
Matcher matcher = Pattern.compile(pattern).matcher(str);
if(matcher.matches()) {
replaceString = "";
for(int i=1;i<=matcher.groupCount();i++) {
String replaceTarget = matcher.group(i);
if(i == 2) {
char[] c = new char[replaceTarget.length()];
Arrays.fill(c, '*');
replaceString = replaceString + String.valueOf(c);
} else {
replaceString = replaceString + replaceTarget;
}
}
}
return replaceString;
}