What is the regular expression in Java for splitting a String like: [space]0[space]
(space followed by zero followed by space)?
eg
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5
splits as:
123456789101112131415
and
12345
String[] split = string.split(" 0 ");
Unless you meant "any whitespace" when you said space. Or "a sequence of one or more space characters".
If you don't mind having some extra spaces: \\b0\\b
.
If you do want to remove spaces, this should work for the start and end zeros as well: \\s?\\b0\\b\\s?
这应该有效:
string.split("\\s0\\s");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.