How Can I Get A Regex That Allows Only 0000 Or Spaces
how can I get a regex that allows only 0000 or spaces, but not both examples: 0000000000000000000 --> OK; only spaces --> OK; 000000000 0000 --> Not Ok; a
Solution 1:
^(?:0+| +)$
Explanation:
^ # Start of string
(?: # Either match (but don't capture)...
0+ # one or more zeroes
| # or
[ ]+ # one or more spaces
) # End of non-capturing group (used to contain the alternation)
$ # End of string
Solution 2:
This should work: (0+)|( +)
, doesn't it?
Post a Comment for "How Can I Get A Regex That Allows Only 0000 Or Spaces"