# Regular expression for All strings with exactly two b

## Write a Regular expressions defined over {a, b} for All strings with exactly two b’s.

### Valid strings: (must be accepted by our Regular Expression)

Strings of length 1: No valid strings

Strings of length 2: bb, No other valid strings

Strings of length 3: abb, bba, No other valid strings

Strings of length 4: aabb, baab, abab, baba,……. and many other similar strings.

Strings of length 5: abaab, ababa, aaabb, ababa, aabab, bbaaa,………and many other similar strings.

Note: Many other similar strings of lengths 6, 7, 8. 9, 10 11, ….etc that have exactly two b’s are valid strings. You can try it by yourself.

### Invalid strings: (must be Rejected by our Regular Expression)

Strings of length 1: b, a No other invalid strings

Strings of length 2: aa, ab, ba,  No other invalid strings

Strings of length 3: aaa, bbb, aab, baa, bab, aba, No other invalid strings

Note: All other strings defined over {a, b) that have not exactly two b’s are invalid strings. You can try it by yourself.

b* a b* a b*

1* 0 1* 0 1*

0* 1 0* 1 0*