I’m trying to pull out all strings which have an even number of B’s and an odd number of C’s. I have the regexes to match odd A’s and even B’s but I cannot get the two to work together. The strings are delimited by whitespace (tabs, newlines, spaces).
e.g.
XABBAC ABCDEBCC ABSDERERES ABBAAJSER HGABAA
I have for odd A’s
\b[^A]*A([^A]*A[^A]*A)*[^A]*\b
And for even B’s
\b[^B]*(B[^B]*B[^B]*)*[^B]*\b
I know I need to use +ve lookahead and have tried:
\b(?=[^A]*A([^A]*A[^A]*A)*[^A]*\b)[^B]*(B[^B]*B[^B]*)*[^B]*\b
but it doesn’t work – does anybody know why?
The problem is that your regexes (regexen?) can match zero characters –
\b\bwill match on a single word boundary, and so will\b{someregexthatcanmatchzerocharacters}\b.