Code with some oddity handling: (Note that it skips empty tokens in the output loop. It's quick and dirty.) You can add all the characters that you need to split and delete into the regular expression pattern. (tchrist is right. This thing is filled with bitterness and works only in very simple cases.)
public class SomeClass { public static void main(String args[]) { String input = "The\rquick!brown - fox\t\tjumped?over;the,lazy\n,,.. \nsleeping___dog."; for (String s: input.split("[\\p{P} \\t\\n\\r]")){ if (s.equals("")) continue; System.out.println(s); } } } INPUT: The quick!brown - fox jumped?over;the,lazy ,,.. sleeping___dog. OUTPUT: The quick brown fox jumped over the lazy sleeping dog
Paul sasik
source share