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

regex, regex-alternation

Solution

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

They are not the same.

`a*|b*` means "(0 or more `a`s) or (0 or more `b`s)"

`(a|b)*` means "0 or more (`a` or `b`)s"

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)*`.

Problem

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

Original source