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, which works:
/^(A|AB|ABC)?$/
But this is a simplification; in my app A
, B
, and C
are actually long character classes, so I don't want to repeat them over and over. Maybe I'm just not looking at it the right way. I tried this:
/^((AB?)C?)?$/
But that still matches AC
.
Is there a simpler way to do this, that could be extended to (say), ABCD
, ABCDE
, etc.?
Edit: By extend to ABCDE
, I mean it would match: empty string, A
, AB
, ABC
, ABCD
, ABCDE
. Basically, a "starts with" regex.