Java tutorial
public class Main { public static void main(String[] args) { String str = "test from java2s.com"; String delimiters = "\\s+|,\\s*|\\.\\s*"; String[] tokensVal = str.split(delimiters); System.out.println("Count of tokens = " + tokensVal.length); for (String token : tokensVal) { System.out.println(token); } tokensVal = str.split(delimiters, 3); System.out.println("\nCount of tokens = " + tokensVal.length); for (String token : tokensVal) { System.out.println(token); } } }