【发布时间】:2014-06-13 07:45:01
【问题描述】:
我有这个字符串如何拆分 5-28 14:00 - 5-28 18:00 the60s(.corp)。我想用空格分割它,除非空格周围有数字或 -。
我想要的结果是:
1. how
2. to
3. split
4. 5-28 14:00 - 5-28 18:00
5. the60s(.corp)
谢谢。
以下是我的代码:
String str = "how do I split 5-28 14:00 - 5-28 18:00 the60s(.corp)";
str = str.replaceAll("\\s+(?!(?=-|\\d+))", "@");
首先我用 @ 替换右边的空格,然后用 @ 分割字符串。但它不起作用。
【问题讨论】:
-
一个好的起点是发布您尝试过的代码,解释什么不起作用,为什么,您期望什么以及发生了什么。
标签: java regex capture-group