This is one of the classic problem in AI.
The problem I posted, is actaully an exercise on segmentation section of the OpenLab on http://www.a-i.com.(You will need to register) I have extended it to some other critera such as 'spaces allowed' to meet more general problems.
I tried runrig's solution and it doesn't work when number of patterns is 6, for the condition that one pattern cannot be part of another pattern.
I am trying to solve this problem myself also, what I am looking for is good design to begin with.
(My computer doesn't keep the login for more than one page,
Please let me know if you know the soltuion).