Alternation is about Union, then if We have R={"a"} , S={"b"} , then R|S will be {"a", "b"}.
Why ab, ba are included there in (a|b)*?
I don't understand why
I think the result set should be
(a|b)* = {Ɛ,"a", "b", "aa","bb", "aaa", "bbb", ...}
The expression a|b
matches either a
or b
.
The expression (a|b)*
matches for example (a|b) (a|b) (a|b)
. In each of these alternatives, you can choose individually whether to match a
or b
. You don't have to choose the same for all of them.
The variant "either a*
or b*
" is written exactly as pronounced: a*|b*
.