/*
Number of tokens: 5
A
B
C
D
E
*/
public class MainClass {
public static void main(String[] unused) {
String text = "A B, C, D. E"; // String to segment
String delimiters = "\\s+|,\\s*|\\.\\s*";
// Analyze the string
String[] tokens = text.split(delimiters);
// Output the tokens
System.out.println("Number of tokens: " + tokens.length);
for(String token : tokens) {
System.out.println(token);
} }
}
|