美文网首页Java开发
Java 根据标点符号与空格分割字符串

Java 根据标点符号与空格分割字符串

作者: _浅墨_ | 来源:发表于2021-12-03 11:14 被阅读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]

相关文章

网友评论

    本文标题:Java 根据标点符号与空格分割字符串

    本文链接:https://www.haomeiwen.com/subject/gcvpxrtx.html