Java 中的 Matcher appendTail() 方法(附带示例)
java.util.regex.Matcher 类表示执行各种匹配操作的引擎。此类没有构造函数,你可以使用 java.util.regex.Pattern 类的 matches() 方法创建/获取此类的对象。
此 (Matcher) 类的 appendTail() 方法接受 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>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP