String = ""
String = " "
String = "0"
I need regex to match all three scenario.
I got the first two as
How do I include the check for the zero?
This will match the empty string, a single zero, or all whitespace:
^start of the string
(start a group:
\s+one or more spaces
)end the group
?match the preceding group zero or one times
$end of the string
Your pattern will match any string that contains any whitespace (e.g. it would consider
"foo bar" a match because of the space in the middle). It doesn't sound like this is what you want.
To match any string that contains only whitespace, a single
0, or the empty string, use this:
You could try something like :
If we don't want to match "00000[...]" or "0 0 0 0[...]" :