I\'m banging my head against a wall. I want a regex that matches: empty string, A, AB, and ABC, but not AC. I have this,
A
AB
ABC
AC
Try this regular expression:
^(A(B(C)?)?)?$
I think you can see the pattern and expand it for ABCD and ABCDE like:
ABCD
ABCDE
^(A(B(C(D)?)?)?)?$ ^(A(B(C(D(E)?)?)?)?)?$
Now each part depends on the preceeding parts (B depends on A, C depends on B, etc.).