class Solution {
    public String solution(String new_id) {
        String answer = new_id.toLowerCase(); // 1๋‹จ๊ณ„

        answer = answer.replaceAll("[^-_.a-z0-9]", ""); // 2๋‹จ๊ณ„
        answer = answer.replaceAll("[.]{2,}", "."); // 3๋‹จ๊ณ„
        answer = answer.replaceAll("^[.]|[.]$", "");    // 4๋‹จ๊ณ„
        
        if (answer.equals("")) {    // 5๋‹จ๊ณ„
            answer += "a";
        }

        if (answer.length() >= 16) {     // 6๋‹จ๊ณ„
            answer = answer.substring(0, 15);
            answer = answer.replaceAll("[.]$","");
        }

        if (answer.length() <= 2) {  // 7๋‹จ๊ณ„
            while (answer.length() < 3) {
                answer += answer.charAt(answer.length()-1);
            }
        }

        return answer;
    }
}

 

๋ฌธ์ œ๋งํฌ : https://school.programmers.co.kr/learn/courses/30/lessons/72410

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ