가능한 중복 사용 :
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();
}
이전에 [답변이 정확하지 않았습니다.] (http://stackoverflow.com/a/1732454/596781). –
@KerrekSB가 말한 바. 그리고 코드를 들여 쓰기가 가능하도록 * 들여 쓰기를 배우십시오. – Johnsyweb
이 작업에 정규식을 사용하지 마십시오. – Adrian