Search code examples
regexwhitespace

Regex for not empty and not whitespace


I am trying to create a regex that will return false if the String pattern contains whitespace or is empty. So far I have this

[^\s] 

I think that will make sure the string does not contain whitespace but I am unsure of how to also check to make sure it is not empty. Any help would be appreciated.


Solution

  • /^$|\s+/ if this matched, there's whitespace or its empty.