# Regular expression for All strings containing exactly one a

## Write a Regular expression defined over {a, b} for All strings containing exactly one a

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

Strings of length 1: a, No other  valid strings

Strings of length 2: ba, ab, No other valid strings

Strings of length 3: bab, No other valid strings

Strings of length 4: abbb, babb, abbb, bbba,……. and many other similar strings.

Strings of length 5: abbbb, abbbb, bbabb, bbbba,……..and many other similar strings.

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

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

Strings of length 1: b No other invalid strings

Strings of length 2: bb, aa, No other invalid strings

Strings of length 3: aba, baa, aab, aaa,……. and many other similar strings.

Note: All other strings defined over {a, b) that have strings not containing exactly one a are valid strings. You can try it by yourself.

Write a Regular expression defined over {a, b} for All strings containing exactly one b

(a)* b ( a)*

Write a Regular expression defined over {0, 1} for All strings containing exactly one 0

(1)* 0 ( 1)*

Write a Regular expression defined over {0, 1} for All strings containing exactly one 1

(0)* 1 ( 0)*