2013-12-16 4 views
1

당신이 볼 수있는 문제가 있다면 궁금 해서요, 많은 'stackoverflow 게시물을 검색했습니다 있지만 대답을 얻지 못했습니다.Java Regex 그룹 Stackoverflow 문제가 발생합니다

저는 결국 C.V와 Job 채용과 일치하는 정규 표현식을 만들려고합니다. 이제 정규 표현식을 사용하여 정규 표현식과 매칭에 대해 배우기 시작했습니다. 나는 일치하는 느낌을 얻기 위해 성공적인 일치를 얻으려고 노력하고 있는데, 내가 말했던 그 다른 것들과 결국 일치 시키지만, 이제는 간단한 것들조차도 작동하지 않는다.

public class RunMatchSequence { 

public static void main(String[] args) { 
    try { 



    String emailRegEx = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*"; 
    // String emailRegEx = "(?s).*"; 
    Pattern pattern = Pattern.compile(emailRegEx); 

    String target= "You can email me at [email protected] or [email protected] to get more info"; 
    String target2="You can email"; 
    java.util.regex.Matcher matcher; { 

    matcher = pattern.matcher(target); 

    while(matcher.find()) { 
     System.out.println("Found a Match" + Matcher.group()); 
     System.out.println("Start position: " + Matcher.start()); 
     System.out.println("End position: " + Matcher.end()); 
      }}} catch (StackOverflowError e) { 
       System.out.println("Stackoverflow"); 
       //JOptionPane.showMessageDialog(null, "Stackoverflow"); 
      } 
} 

} 

패턴을 실행하는 클래스입니다. 다음은 그룹을 보유하는 클래스입니다. 여기는 StackOverflowError가 발생하는 곳입니다. (무한 재귀와 관련이 있다고 생각하지만 해결 방법을 모릅니다.) 편집 : 이제 무한 재귀의 원인이 무엇인지 깨닫습니다. 메서드가 호출되어 무한 calls.So을 피하기 위해 어떤 조건 문을 반환하지만 난 아무 생각하면 Matcher.group를 호출 할 때 그룹 방법은 재귀 때문에

public class Matcher{ 
public static void main(String[] args) { 

    RunMatchSequence.main(args); 

//implements MatchResult { 
// Pattern p = Pattern.compile("a*b"); 
// java.util.regex.Matcher m = p.matcher("aaaaab"); 
// boolean b = m.matches(); 
//} 
    } 

static String group() { 
// TODO Auto-generated method stub 
return group(); 
} 

static int end() { 
// TODO Auto-generated method stub 
return end(); 
} 

static int start() { 
// TODO Auto-generated method stub 
return start(); 
} 

} 
+0

'group()','end()','start()'는 무엇을하고 있을까요? 당신은 그들이 무한 재귀를 초래한다는 것이 맞습니다. 그러나 그들은 어떤 가치관을 가지고 돌아오고 있습니까? – jonhopkins

+0

은 일치 값입니다. 마지막 시작은 문자열의 위치를 ​​보여줍니다. – user2674895

+0

아, 알겠습니다. 그럼 정규 표현식 객체에 대해 많이 알지 못하기 때문에 이러한 값을 얻는 방법에 대한 답을 줄 수는 없지만 검색하면 답을 얻어야합니다. 나는 분명히'return group()/end()/start();'줄을 제거 할 것이다. 당신은 그들과 어디에도 가지 않을 것입니다. – jonhopkins

답변

1

글쎄, 자바 라이브러리는 matcher/pattern api를 지원하고 printline에서 matcher.group()을 호출하면된다. ..... 내 실수는 matcher.group() wi API에 의해 인식되지 않는 자본 M.

그래서이 :

static String group() { 
    // TODO Auto-generated method stub 
    return group(); 
    } 

    static int end() { 
    // TODO Auto-generated method stub 
    return end(); 
    } 

    static int start() { 
    // TODO Auto-generated method stub 
    return start(); 
    } 

는 사용되지 않습니다.

2

, 그것은 충돌이 무엇을 넣지해야하지만, 및 호출 및 호출 ...