본문 바로가기

카테고리 없음

Pattern 과 Matcher

반응형
Pattern 과 Matcher

Matcher와 Patten 그리고 indexOf를 이용하면 문자열의 분석을 쉽게 할 수 있다.

Pattern pattern = Pattern.compile("while|for");
  Matcher matcher = pattern.matcher(file);
  while(matcher.find()){
   String target = file.substring(matcher.end(), file.indexOf("}",matcher.end()));
   subRule(target);
  }

이거 짠다고 하루 투자함 ㅡㅡ;;

ps. jdk 1.5 부터는 Scanner라는 Class도 사용할 수 있습니다.
반응형