I bang my head against the wall. I want a regular expression that matches the empty string, A, ABand ABC, but not AC. I have this one that works:
/^(A|AB|ABC)?$/
But this is a simplification; in my application A, Band Care actually long character classes, so I don’t want to repeat them again and again. Maybe I'm just not looking at it right. I tried this:
/^((AB?)C?)?$/
But it is still consistent AC.
Is there an easier way to do this, which can be extended up to (say) ABCD, ABCDEetc.?
Change . Expanding to ABCDE, I mean that it will match an empty string, A, AB, ABC, ABCD, ABCDE. Basically, it starts with a regular expression.
Jenni source
share