public static void main(String[] args) {
String str = "abcdefgabc";
Pattern pattern = Pattern.compile("abc");
Matcher matcher = pattern.matcher(str);
int i = 0;
while (matcher.find()) {
//matcher.group();
i++;
}
System.out.println(i);
}
String[] test ={"abcabc","abcadc", "abc/nabc"};
String X="abc";
String reg="^(?is)(?:(?!" + X + ").)*" + X + "(?:(?!" + X + ").)*$";
for(String s : test){
Matcher m = Pattern.compile(reg).matcher(s);
if(m.find()){ System.out.println("源字符串:" + s + " 匹配结果: " + true);
}else{
System.out.println("源字符串:" + s + " 匹配结果: " + false);
}
}