Java의 정규표현식 관련 객체인 Matcher와 Pattern을 이용한다.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// 괄호 패턴, 공백 패턴 생성
private static final Pattern PATTERN_BRACKET = Pattern.compile("\\([^\\(\\)]+\\)");
private static final String VOID = "";
private static String deleteBracket(String text) {
Matcher matcher = PATTERN_BRACKET.matcher(text);
String pureText = text;
String removeTextArea = new String();
while(matcher.find()) {
int startIndex = matcher.start();
int endIndex = matcher.end();
removeTextArea = pureText.substring(startIndex, endIndex);
pureText = pureText.replace(removeTextArea, VOID);
matcher = PATTERN_BRACKET.matcher(pureText);
}
return pureText;
}