String html = "htmlString";//你得到的html字符串 Pattern p = Pattern.compile("\\{\\$abc\\}"); Matcher m = p.matcher(html); int i = 0; while(m.find()){ i++; } //i的结果为{$abc}出现的次数 //替换你就自己写了
public class Test29 { public static void main(String[] args) { String s = "asaasasas{$abc}jaskls{$abc}jklal{$abc}jsa"; Pattern p = Pattern.compile("\\{\\$abc\\}"); Matcher m = p.matcher(s); while(m.find()){ System.out.println(m.group()); } } }
Pattern p = Pattern.compile("\\{\\$abc\\}");
Matcher m = p.matcher(html);
int i = 0;
while(m.find()){
i++;
}
//i的结果为{$abc}出现的次数
//替换你就自己写了
我看API上用groupCount()方法应该能得到的.可是我用的时候.一直得到的是0.
public static void main(String[] args) {
String s = "asaasasas{$abc}jaskls{$abc}jklal{$abc}jsa";
Pattern p = Pattern.compile("\\{\\$abc\\}");
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group());
}
}
}