String p = "(a|ab|c)*";
String s = "aabcab";
Boolean b = s.matches(p);
System.out.println(b);
This pattern 'p' matches:
1) 0 or more single 'a': a, aa, aaa
2) 0 or more single 'ab': ab, abab, ababab
3) 0 or more single 'c': c, cc, ccc
Why does it match 'aabcab'? In the 3 patterns above, there isn't any string consisting of a mixture of characters 'a', 'b', and 'c'