Is (a|b)* the same as a*|b*? In other words, does (a|b)* accept string which are combinations of as and bs?
Asked
Active
Viewed 7,849 times
8
Unihedron
- 10,902
- 13
- 62
- 72
Rick Sanchez
- 4,528
- 2
- 27
- 53
-
1I'm Mr. Meeseeks, look at meee! – Mr. Meeseeks Jan 19 '16 at 21:26
-
1@meeseeks wubalubadubdub!!! – Rick Sanchez Jan 19 '16 at 21:28
3 Answers
11
Is
(a|b)*the same asa*|b*?
They are not the same.
a*|b*means "(0 or moreas) or (0 or morebs)"(a|b)*means "0 or more (aorb)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)*.
arshajii
- 127,459
- 24
- 238
- 287
9
No.
In case of (a|b)*, you can mix As and Bs (see demo).
In case of a*|b*, you can have either As or Bs (see demo).
Amal Murali
- 75,622
- 18
- 128
- 150
vittore
- 17,449
- 6
- 44
- 82
0
a*|b* denotes {ε, "a", "b", "aa", "bb", "aaa", "bbb", ...}
(a|b)* denotes {ε, "a", "b", "aa", "ab", "ba", "bb", "aaa", aab, abb, aba, baa ...}
ε denote empty
Szczerski
- 839
- 11
- 11