Java 根据标点符号与空格分割字符串
2021-12-03 本文已影响0人
_浅墨_
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]