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
/^A(?:B(?:C)?)?$/
should do it.
This is using the non-capturing group construct (?: xxx ) so as not to mess up any match capturing you may be doing.
(?: xxx )