2012-01-22 3 views
0

가능한 중복 사용 :
RegEx match open tags except XHTML self-contained tags데이터를 추출 자바 정규식을

I have this list of 100 names to be extracted that lie in between the tags. I need to extract just the data and not the tags using Java Regular Expressions. 

예 : 나는 데이터 아론, TEB, 아바, 직 ì 필요 , Abashidze, 해리. 모두 새로운 줄에.

<a class="listing" href=http://eeee/a/hank_aaron/index.html">Aaron, Teb</a><br> 
    <a class="listing" href=http://eeee/t/sani_abacha/index.html">Abacha, Jui</a><br> 
    <a class="listing" href=http://eeee/i/aslan_abashidze/index.html">Abashidze, Harry</a><br> 

다음 코드를 작성했지만 태그도 추출합니다. 나는 어디로 잘못 가고있어. 어떻게하면 태그를 바꾸거나 Regexp가 잘못 되었습니까?

public static void main(String[] args) throws Exception { 
    URL oracle = new URL("http://eeee/all/people/index.html"); 
    BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream())); 
    String input; 
    String REGEX = "<a class=\"listing\"[^>]*>"; 
    while ((input = in.readLine()) != null){ 
     Pattern p = Pattern.compile(REGEX); 
     Matcher m = p.matcher(input); 
     while(m.find()) { 
      System.out.println(input); 
     } 
    } 
    in.close(); 
} 
+2

이전에 [답변이 정확하지 않았습니다.] (http://stackoverflow.com/a/1732454/596781). –

+1

@KerrekSB가 말한 바. 그리고 코드를 들여 쓰기가 가능하도록 * 들여 쓰기를 배우십시오. – Johnsyweb

+2

이 작업에 정규식을 사용하지 마십시오. – Adrian

답변

0

사용이 정규 표현식 :

(?:<a class=\"listing\"[^>]*>)([^<]*)(?:<) 

그 그룹 1은 이름을 캡처합니다.

P. 루프 외부로 Pattern p = Pattern.compile(REGEX);을 이동해야합니다.

+0

: 답변 해 주셔서 감사합니다. 그것은 내 문제를 해결했다. 고맙습니다. –

관련 문제