I am splitting below string with multiple delimiters. Delimiters are:
, . @ ? ! _ ' and white space etc.
Below is my code:
String[] tokens = s.split("[!|?|,|.|_|'|@ |\\s]");
For input: He is a very very good boy, isn't he?
Expected output after split is: 10 tokens He is a very very good boy isn t he
But I am getting below ouput: 11 tokens He is a very very good boy
isn t he
Because two delimiters whitespace and comma are adjacent, it is giving 11 tokens. How to get expected output?
Aucun commentaire:
Enregistrer un commentaire