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?
Is (a|b)* the same as a*|b*?
Asked Answered
I'm Mr. Meeseeks, look at meee! –
Slowworm
@meeseeks wubalubadubdub!!! –
Thurmond
Is
(a|b)*
the same asa*|b*
?
They are not the same.
a*|b*
means "(0 or morea
s) or (0 or moreb
s)"(a|b)*
means "0 or more (a
orb
)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)*
.
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
© 2022 - 2024 — McMap. All rights reserved.