I\'ve seen posts here on stackoverflow that say that the regex ^$ will match an empty string... So it made me think... why not something like this: ^\\s+$
^\s+$- does that not also work?
Not for matching an empty string. In general, X+ means X one or more times. So, \s+ cannot match the empty string - it requires at least one \s in order to match.
^ \s + $
| | | |
start of string ---------------------+ | | |
whitespace character ------------------+ | |
one or more of what precedes -------------+ |
end of string ------------------------------+
Now, X* means X 0 or more times, so ^\s*$ would indeed match an empty string.
^\s+$
^\s*$