Zinedin Zidane
Zinedin Zidane

Reputation: 112

Regular Expression of Language {a b} which contains string of Odd Length and must contain atleast one 'b' in it

I've tried the following solution but it may not cover all the strings

b(aa+ab+ba+bb)* + (aa+ab+ba+bb)*b

here + means OR operation and * means repetition.

Can someone debug the above regex?

Upvotes: 0

Views: 965

Answers (2)

Adnan Qureshi
Adnan Qureshi

Reputation: 562

RE = (a+b)((a+b)(a+b))*b(a+b)((a+b)(a+b))* + ((a+b)(a+b))*b((a+b)(a+b))*

I hope it will cover all strings

Upvotes: 1

sabeen kanwal
sabeen kanwal

Reputation: 607

check out this ..

b((a+b)(a+b))*

this results in generating strings with minimum length 1 i-e odd as per your requirement also containing (b);if you take closure once

for more than 1 odd lengths take closure multiple times

Upvotes: 0

Related Questions