What regex pattern would need I to pass to the java.lang.String.split()
method to split a String into an Array of substrings using all whitespace characters (' ', '\t', '\n', etc.) as delimiters?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Something in the lines of
This groups all white spaces as a delimiter.
So if I have the string:
"Hello[space][tab]World"
This should yield the strings
"Hello"
and"World"
and omit the empty space between the[space]
and the[tab]
.As VonC pointed out, the backslash should be escaped, because Java would first try to escape the string to a special character, and send that to be parsed. What you want, is the literal
"\s"
, which means, you need to pass"\\s"
. It can get a bit confusing.The
\\s
is equivalent to[ \\t\\n\\x0B\\f\\r]
Apache Commons Lang has a method to split a string with whitespace characters as delimiters:
http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#split(java.lang.String)
This might be easier to use than a regex pattern.
Since it is a regular expression, and i'm assuming u would also not want non-alphanumeric chars like commas, dots, etc that could be surrounded by blanks (e.g. "one , two" should give [one][two]), it should be:
To get this working in Javascript, I had to do the following:
Study this code.. good luck