Search code examples
regexregular-language

Regular Expression for Strings with even number of b's followed by the letter c followed by an odd number of a's


I have managed to figure out the regular expression for even number of b's and odd number of a's through (bb|aa|(ba|ab)(bb|aa)*(ab|ba))*(a|(ba|ab)(aa|bb)*b)

What if I need the following sequence:

  1. Even number of b's
  2. Followed by the letter 'C'
  3. Followed by odd number of a's

any idea?


Solution

  • Try this (zero is an even number):

    ^(bb)*ca(aa)*$