java - How do I split a string with any whitespace chars as delimiters? -
what regex pattern need pass java.lang.string.split()
method split string array of substrings using whitespace characters (' ', '\t', '\n', etc.) delimiters?
something in lines of
mystring.split("\\s+");
this groups white spaces delimiter.
so if have string:
"hello[space][tab]world"
this should yield strings "hello"
, "world"
, omit empty space between [space]
, [tab]
.
as vonc pointed out, backslash should escaped, because java first try escape string special character, , send that parsed. want, literal "\s"
, means, need pass "\\s"
. can bit confusing.
the \\s
equivalent [ \\t\\n\\x0b\\f\\r]
Comments
Post a Comment