Abdelrahman Wahdan
Abdelrahman Wahdan

Reputation: 2065

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?

Upvotes: 0

Views: 963

Answers (2)

Ishak Shaik
Ishak Shaik

Reputation: 1

Expression for even no. of b's: (bb)*
Expression for odd no. of a's: (aa)*a
So the overall regular expression is: (bb)*c(aa)*a

Upvotes: 0

Bohemian
Bohemian

Reputation: 425063

Try this (zero is an even number):

^(bb)*ca(aa)*$

Upvotes: 2

Related Questions