import java.util.Arrays; public class Main{ public static void main(String[] args) throws Exception { String string = "How dare you! You have lost him two days ago:'("; String regex = " |(?<! |\\p{Punct})(?=\\p{Punct})|(?<=\\p{Punct})(?!\\p{Punct})"; System.out.println(Arrays.asList(string.split(regex))); }}
Standard input is empty
[How, dare, you, !, You, have, lost, him, two, days, ago, :'(]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!