I need a Java regular expression, which checks that the given String is not Empty. However the expression should ingnore if the user has accidentally given whitespace in the beginning of the input, but allow whitespaces later on. Also the expression should allow scandinavian letters, Ä,Ö and so on, both lower and uppercase.
I have googled, but nothing seems ro quite fit on my needs. Please help.
∅, the empty set, is a regular expression. ∅ represent the language with no elements {}.
An empty regular expression matches everything.
The most common regex character to find whitespaces are \s and \s+ . The difference between these regex characters is that \s represents a single whitespace character while \s+ represents multiple whitespaces in a string.
You can also use positive lookahead assertion to assert that the string has atleast one non-whitespace character:
^(?=\s*\S).*$
In Java you need
"^(?=\\s*\\S).*$"
For a non empty String use .+
.
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