java.util.regex.Matcher 클래스는 다양한 일치 작업을 수행하는 엔진을 나타냅니다. 이 클래스에 대한 생성자가 없습니다. java.util.regex.Pattern 클래스의 match() 메소드를 사용하여 이 클래스의 객체를 생성/얻을 수 있습니다.
appendTail() 이 (Matcher) 클래스의 메소드는 StringBuffer 객체를 받아들이고 여기에 입력 시퀀스의 문자를 추가합니다.
예시
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AppendTail {
public static void main(String[] args) {
String str = "<p>This <b>is</b> an <b>example</b> HTML <b>script</b>.</p>";
//Regular expression to match contents of the bold tags
String regex = "<b>(\\S+)</b>";
//Creating a pattern object
Pattern pattern = Pattern.compile(regex);
//Matching the compiled pattern in the String
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
matcher.appendTail(sb);
while (matcher.find()) {
System.out.println(matcher.group(1));
}
System.out.println("Contents of the StringBuffer: \n"+ sb);
}
} 출력
StringBuffer의is example script Contents of the StringBuffer: <p>This <b>is</b> an <b>example</b> HTML <b>script</b>.</p>