Java string.split – by multiple character delimiter [duplicate]

String.split takes a regular expression, in this case, you want non-word characters (regex \W) to be the split, so it’s simply:

String input = "Hi,X How-how are:any you?";
String[] parts = input.split("[\\W]");

If you wanted to be more explicit, you could use the exact characters in the expression:

String[] parts = input.split("[,\\s\\-:\\?]");

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)