English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Thisfrom java.util.regex.MatcherThis class represents an engine for performing various matching operations. This class has no constructor and can be usedmatches()
The method of class java.util.regex.Pattern creates/Get an object of this class.
The (Matcher) classappendTail()The method accepts a StringBuffer object and appends the characters of the input sequence to the object.
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 the content of bold tags String regex = "<b>(\\S+)</b>"; //Create a pattern object Pattern pattern = Pattern.compile(regex); //Match 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); } }
Output Result
is example script Contents of the StringBuffer: <p>This <b>is</b> an <b>example</b> HTML <b>script</b>.</p>