[필수개념]
> 정규화, 꼭 알아야함
class Solution {
public String solution(String new_id) {
String answer = "";
String temp = new_id.toLowerCase();
//^ : 앞의 문자들 제외
// 제외하고 모두 ""으로 처리하겠다
temp = temp.replaceAll("[^-_.a-z0-9]","");
//2개 이상의 .들을 모두 제외
temp = temp.replaceAll("[.]{2,}",".");
//첫자리 끝자리 . 들 모두 제외
temp = temp.replaceAll("^[.]|[.]$","");
//문자열 공백이면 "a"추가
if(temp.equals(""))
temp+="a";
//문자열 16이상이면 15까지만 출력하고 첫자리 끝자리 . 제외
if(temp.length() >=16){
temp = temp.substring(0,15);
temp=temp.replaceAll("^[.]|[.]$","");
}
// 문자열 2개 이하이면 끝자리 추가
if(temp.length()<=2)
while(temp.length()<3)
temp+=temp.charAt(temp.length()-1);
answer=temp;
return answer;
}
}
public class Hello {
public static void main(String[] args) {
Solution test = new Solution();
String o = "...!@BaT#*..y.abcdefghijklm";
System.out.println(test.solution(o));
}
}
'프로그래머 ,백준, 유튜브, 문제' 카테고리의 다른 글
K번째 수_프로그래머스 (0) | 2022.09.27 |
---|---|
최대공약수와 최소공배수_프로그래머스 (0) | 2022.09.27 |
시저암호_프로그래머스 (0) | 2022.09.26 |
소수만들기_프로그래머스 (1) | 2022.09.26 |
문자열 내 마음대로 정렬하기_프로그래머스 (1) | 2022.09.26 |
댓글