\s stands for “whitespace character”. Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a carriage return, a line feed, or a form feed.
The \s metacharacter matches whitespace character. Whitespace characters can be: A space character.
The Java regex pattern \\s+ is used to match multiple whitespace characters when applying a regex search to your specified value. The pattern is a modified version of \\s which is used to match a single whitespace character.
Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself. Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the anchor for the start of the string, or the negation symbol.
\s
matches whitespace (spaces, tabs and new lines). \S
is negated \s
.
\S
matches anything but a whitespace, according to this reference.
I believe it means 'anything but a whitespace character'.
/\S/.test(string)
returns true if and only if there's a non-space character in string
. Tab and newline count as spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With