Java regex "\\s+"
In Java, the regular expression \\s+
is used to match one or more whitespace characters, including space, tab, newline, carriage return, etc.
The \\
is an escape character used to indicate that the following character is a special character in the regular expression. In this case, the special character is s
, which represents whitespace. The +
is a quantifier that matches one or more occurrences of the preceding whitespace character.
So, split("\\s+")
will split a string into an array of substrings based on one or more whitespace characters. The double backslash is necessary because the backslash character itself is also an escape character in Java strings, so we need to escape it with another backslash to indicate that we want a single backslash character in the regular expression.
Last updated