62,620
社区成员
发帖
与我相关
我的任务
分享import java.util.regex.Pattern;
public class MatcherDuplication {
public static void main(String[] args) {
String[] strs = {
"12365abbcdnt1234",
"12365cdnt1234",
"12356abcabc1234"
};
String regex = "(?:[^abc]*([abc])(?!\\1))*[^abc]*";
Pattern pattern = Pattern.compile(regex);
for(int i = 0; i < strs.length; i++) {
System.out.println(strs[i] + " --> " + pattern.matcher(strs[i]).matches());
}
}
}
String s = "11ab";
Pattern p = Pattern.compile("[abc]{2,}");
System.out.println(!p.matcher(s).find());