Split multiple delimiters in Java

The split method takes as argument a regular expression so, to use multiple delimiters, you need to input a regular expression separated by the OR regex operator or using a character class (only if the delimiters are single characters).

Using the OR operator:

String delimiters = "\\t|,|;|\\.|\\?|!|-|:|@|\\[|\\]|\\(|\\)|\\{|\\}|_|\\*|/";

Using the character class:

String delimiters = "[-\\t,;.?!:@\\[\\](){}_*/]";

As you can see some of the characters must be escaped as they are regex metacharacters.


Try with

split("\\t|,|;|\\.|\\?|!|-|:|@|\\[|\\]|\\(|\\)|\\{|\\}|_|\\*|/");

Also

Use String.split() with multiple delimiters