请教如何用正则表达式将一个字符串按照空格和逗号分割!!

airhawk 2004-12-05 11:11:30
譬如说 我有这样一个字符串
String strTemp="This is a test, and that is also a test.";
String strSplit[]=strTemp.split(正则表达式),split 成
This
is
a
test
and
that
is
also
a
test.
就是将字符串有空格或者, (逗号)都要分割。
高手指点。
...全文
1000 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
airhawk 2004-12-07
  • 打赏
  • 举报
回复
to thomas_20() :谢谢你,这个格式什么含义能不能解释一下啊?你的,我试了,是对的。
icy_csdn 2004-12-06
  • 打赏
  • 举报
回复
抱歉,应该是
String strSplit[]=strTemp.split("\\s*,?\\s+");
icy_csdn 2004-12-06
  • 打赏
  • 举报
回复
String strSplit[]=strTemp.split("\\s+|,");
icy_csdn 2004-12-06
  • 打赏
  • 举报
回复
String strSplit[]=strTemp.split("\\s+");
kaymo 2004-12-06
  • 打赏
  • 举报
回复
按2个分割不知道
up
thomas_20 2004-12-06
  • 打赏
  • 举报
回复
改这样吧,不好意思
String[] strSplit=strTemp.split("(\\s*,\\s*|\\s+)");
thomas_20 2004-12-06
  • 打赏
  • 举报
回复
完整一点:
String[] strSplit=strTemp.split("(\\s+,?|,?\\s+)");
^_^
thomas_20 2004-12-06
  • 打赏
  • 举报
回复
String[] strSplit=strTemp.split("(\\s+|,)");

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧