String[] words = {"a","ab","ac","abc","aac","aa"};
for(String str:words) {
if(str.matches("[abc]+")) {
System.out.println(str);
}
}
This code print out
a,ab,ac,abc,aac,aa
This is almost what I want except I do not want a letter be matched twice. I want to change the regex [abc]+
so that the match will only happen once. The aac
and aa
should not printed because aa
is matched twice.
Can I do this?