The code
String s = \"y z a a a b c c z\"; Pattern p = Pattern.compile(\"(a )+(b )+(c *)c\"); Matcher m = p.matcher(s); while (m.find()) { System.out.pri
You will need a lazy quantifier.
Please try the following:
Pattern p = Pattern.compile("(a )+(b )+((c )*?)c");
Please also notice, that I grouped "c" once again, since I think that's what you want. Otherwise you would find arbitrarily many spaces, but not "c".
c