java.util.regex.Matcher class แสดงถึงเอ็นจิ้นที่ดำเนินการจับคู่ต่างๆ ไม่มีตัวสร้างสำหรับคลาสนี้ คุณสามารถสร้าง/รับวัตถุของคลาสนี้โดยใช้เมธอดmatch() ของคลาส java.util.regex.Pattern
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);
}
} ผลลัพธ์
is example script Contents of the StringBuffer: <p>This <b>is</b> an <b>example</b> HTML <b>script</b>.</p>