Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From what I understand the regular expression (a* + b*) . (a.b)* accepts the following strings:

Empty string, aaaaaaaaaababab, bbbbbbbbbbabab, aabab, babab, etc with different lengths of a, b and ab.

Do I have it right?

share|cite|improve this question
up vote 2 down vote accepted

Yes. $a^*+b^*$ gets you all strings that do not contain both $a$ and $b$, so you get the strings $a^n$ and $b^n$ for $n\ge 0$. $(ab)^*$ gets you $(ab)^n$ for all $n\ge 0$. Thus, $(a^*+b^*)(ab)^*$ gives you the strings $a^m(ab)^m$ and $b^n(ab)^m$ for $m,n\ge 0$.

The easiest way to check a string $w$ is to start processing it from the back. Find the maximum word $u$ of the form $(ab)^n$ that is a final segment of $w$: $u=(ab)^n$ for some $n\ge 0$, and $w=xu$ for some $x$. If $x$ has the form $a^*$ or $b^*$, then $w$ matches $(a^*+b^*)(ab)^*$; if not, it doesn’t.

share|cite|improve this answer
Thank you again. – zeqof Oct 18 '12 at 6:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.