import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Count2 {
public static void main(String[] args) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(“D:\index.txt”));
StringBuffer sb = new StringBuffer();
String str = null;
while ((str = br.readLine()) != null) {
sb.append(str);
}
String[] regex = new String[] { “<div”, “<span”, “<nz-input-group”, “<input”, “<ng-template”, “<i”, “<h1”,
“<h2”, “<h3”, “<h4”, “<p”, “<button”, “<nz-autocomplete”, “<strong”, “<a”, “<label”, “<ul”, “<li”,
“<ng-container”, “<nz-spin”, “<img”, “<nz-anchor”, “<nz-link”, “<hr”, “<textarea”, “<h”,
“<nz-select”, “<nz-pagination”, “<nz-table”, “<tr”, “<th”, “<thead”, “<tbody”, “<td”, “<nz-modal” };
for (int i = 0; i < regex.length; i++) {
Pattern pattern = Pattern.compile(regex[i]);
Matcher matcher = pattern.matcher(sb);
int num = 0;
while (matcher.find()) {
num++;
}
if (num != 0) {
System.out.println(regex[i] + ": " + num);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != br) {
// 关闭资源
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}