Split string by punctuation marks in Java
示例:
String text="Some\u00a0words stick together⁈";
String[] res1 = text.split("[\\p{Punct}\\s]+");
System.out.println(Arrays.toString(res1));
String[] res2 = text.split("[\\p{IsPunctuation}\\p{IsWhite_Space}]+");
System.out.println(Arrays.toString(res2));
输出结果:
[Some words, stick, together⁈]
[Some, words, stick, together]
网友评论