2016-07-12 2 views
-1

html 문서에 아래와 같은 모든 태그 (모든 태그 코드는 <>에 포함)를 가져오고 싶습니다. /<.+>/으로 시도했지만 작동하지 않는 것 같습니다.정규 표현식으로 html로 태그 코드 받기

<table class="body wrap" cellpadding="0" cellspacing="0" align="center" style="width: 100%;max-width: 600px;background-color: #f4f4f4;"> 

어떻게하면됩니까?

+0

아래의 모든 태그는 무엇을 의미합니까? 태그의 어떤 부분이 일치하는 부분에 포함되어야합니까? – 10100111001

+0

전체

태그 (이 경우)와 다른 모든 태그를 큰 html 문서에서 가져옵니다. – zonyang

+0

'/ <[^<>] +> /'이상'/ <.+?> /' – horcrux

답변

0

이렇게하면됩니다.

import java.util.regex.Pattern; 
import java.util.regex.Matcher; 
public class HTMLTagMatcher 
{ 
    private static final String REGEX = "<[^\\/][^<>]+>"; 
    private static final String INPUT = "<test><blah /><test2></test><best><blargh></best><outside>"; 

    public static void main(String[] args) { 
    Pattern p = Pattern.compile(REGEX); 
    Matcher match = p.matcher(INPUT); 
    while (match.find()) { 
     System.out.println(match.group()); 
    } 
    } 
} 
관련 문제