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
The only way I can think of here would be to generate a list of all possible substrings of your original string and match the regex against each of them, retaining those items where it matched.