Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个字符串
s ="[ 2323.2323 232.3232 0.2 0.3 3232]"
我想通过空格分隔符将其拆分为字符串数组。我还想在值之间保留一个空格并忽略多个空格。
执行此操作的正则表达式是什么?
首先去掉多个空格:
String after = before.trim().replaceAll(" +", " ");
然后使用 split 方法将字符串拆分到您的数组中