regexregex-alternation

Is (a|b)* the same as a*|b*?


Is (a|b)* the same as a*|b*? In other words, does (a|b)* accept string which are combinations of as and bs?


Solution

  • Is (a|b)* the same as a*|b*?

    They are not the same.

    So, for example, ab will be matched by (a|b)* but not by a*|b*. Note also that anything matched by a*|b* will also be matched by (a|b)*.