티스토리 뷰

오류메세지

Unclosed character class near index 0 [

java.util.regex.PatternSyntaxException: Illegal repetition {

 

String java.lang.String.replaceAll(String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with thegiven replacement. 

 

replaceAll 메서드가 문자열을 치환할 때 regex(정규표현식)을 이용하기 때문에 발생하는 오류로 괄호 앞에 \\를 붙여 치환해주면 된다.

string1 = string1.replaceAll("[", "");   //오류
string1 = string1.replaceAll("\\[", ""); //수정


string2 = string2.replaceAll("{", "");   //오류
string2 = string2.replaceAll("\\{", ""); //수정

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함