I would like to write a regex to fulfil following requirements:
| Test case | Test string | Is Valid |
|---|---|---|
| 1 | board add 0/1 aaa |
True |
| 2 | board add 0/1 xxx |
False |
| 3 | EMPTY_STRING |
True |
| 4 | |
True |
| 5 | board add 0/2 aaa |
True |
Then, I decided to build the regex with python by make use of
(?(xxx)YES-PATTERN|NO-PATTERN)
I come up with following
(board add 0/1)?(?(1) (aaa|bbb))- If
(board add 0/1)exists, we check whether it followsaaaorbbb - If
(board add 0/1)does not exists, we make it pass
- If
But, the regex above just does not work as expected. It failed on test case 2. Anyone know how to fix it?
You can check my regex by following url
'xxx' not in string^(?!.*\bboard add 0/1 (?!aaa|bbb)).*