Java tutorial
public class Main { public static void main(String args[]) { String statement = " a b c abc bca cba"; String tokens[] = null; String splitPattern = "a|abc|bac|" + "b|(c)|(cba)"; tokens = statement.split(splitPattern); for (int i = 0; i < tokens.length; i++) { System.out.println(tokens[i]); } } }