I want to be able to use a file containing only A's and B's and using only a regex be able to only allow sections with an even number of A's and either odd or even for B's. The A's can be separated by B's and don't have to be in sets of 2.
Here are some examples:
AABBABA -> pass
BABBAB -> pass
BABAAB -> fail
BABBBA -> pass
The following regex pattern seems to work well:
This matches the pattern
AB*AB*zero or more times in the middle, with optionalBon both ends. Check the demo to see it working correctly.Demo