정규식 (2) 썸네일형 리스트형 정규식 공백 무시 다음은 정규식의 초 간단 공백 무시 방법 입니다. while\\s*\\(|for\\s*\\( 위와 같이 쓰면 while 이나 for 다음에 공백이 나오면 무시하고 "(" 괄호를 포함 하는 곳을 찾습니다. while ( while( 위의 모두를 찾는다는 예기 입니다. while\\s{3}tt 이렇게 하면 while 다음에 공백이 3개 있고 그 다음 tt 로 된 문자열을 찾는다는 예기 입니다. 참고로 자바에서 정규식을 사용할때는 \s --> \\s 와 같이 \를 하나 더 붙여 주어야 합니다. 새롭게 또 만든 정규식 입니다. 다음은 while | for 문 다음에 { 를 찾아서 while | for문과 { 사이의 문자열을 Return 합니다. while[^\\{]*|for[^\\{]* 이번은 while이나 f.. 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도 사용할 수 있습니다. 이전 1 다음