Your line will be a prefix followed by a followed by a suffix.
Both prefixes and suffixes can be zero length. If not, they should be either even or both uneven. This means that you have two main cases.
EVENPREFIX a EVENSUFFIX | UNEVENPREFIX a UNEVENSUFFIX
Try ( incomplete and incorrect ):
([bc][bc])*a([bc][bc])*|([bc][bc][bc])*a([bc][bc][bc])*
There remains one more uneven case: one [bc] :
(([bc][bc])*a([bc][bc])*)|([bc]([bc][bc])*a[bc]([bc][bc])*)
According to http://www.fileformat.info/tool/regex.htm , this is consistent
I expect this to fit the rest too ...
The left side guarantees even (or empty) sequences b or c . The right side is either a single b or c , followed by several of the two (so that it remains uneven).
Kobe came up with this refinement above:
([bc][bc])*(a|[bc]a[bc])([bc][bc])*
How it works?
The first group is guaranteed to be even. The second group is guaranteed to be uneven with one a inside. The third group is guaranteed to be even. Thus, it is guaranteed that everything will be uneven.
Daren thomas
source share