class Solution {
public String solution(String new_id) {
new_id = new_id.toLowerCase();
new_id = new_id.replaceAll("[^0-9a-z\\-_.]", "");
new_id = new_id.replaceAll("\\.+", ".");
new_id = new_id.replaceAll("^\\.+|\\.+$", "");
if (new_id.isEmpty()) new_id = "a";
if (new_id.length() >= 16) new_id = new_id.substring(0, 15);
new_id = new_id.replaceAll("\\.+$", "");
while (new_id.length() < 3) {
new_id += new_id.charAt(new_id.length() - 1);
}
return new_id;
}
}
'Coding Test > 프로그래머스' 카테고리의 다른 글
[프로그래머스/자바] 푸드 파이트 대회 (0) | 2023.11.27 |
---|---|
[프로그래머스/자바] 쿼드압축 후 개수 세기 (0) | 2023.11.27 |
[프로그래머스/자바] 문자열 내 p와 y의 개수 (0) | 2023.11.27 |
[프로그래머스/자바] 문자열 압축 (0) | 2023.11.27 |
[프로그래머스/자바] 이상한 문자 만들기 (1) | 2023.11.27 |