Just as a slightly longer explanation: \S
is a metacharacter which is interpreted as /[^ \t\r\n\f]/
, whereas \s
is a metacharacter which is interpreted as /[ \t\r\n\f]/
-> Documentation
So the interpretation of the characters is exactly opposite, which means if you are inverting one of the two, you'll get exactly the same matching behaviour.
And that means yes, you can substitute [^\s]
in your regular expression with \S
.