Regular expression that accept the language of all binary strings with exactly two $a$’s and at least one $b$.

1.1k Views Asked by At

I need to design a regular expression that accept the language of all binary strings with exactly two a’s and at least one b.

Here's what I've got so far:

$(aab^+) \cup (ab^+a) \cup (b^+aa) \cup (ab^+ab^+) \cup (b^+aab^+) \cup (b^+ab^+a)$

But this makes very little sense.

How do I approach this correctly?

1

There are 1 best solutions below

0
On

If it weren't for the requirement that there be at least one $b$, you could use $$b^*ab^*ab^*,$$ but there has to be a $b$ somewhere. So we have $$b^+ab^*ab^*\cup b^*ab^+ab^*\cup b^*ab^*ab^+.$$