Reputation:
Would there be a difference between (aa)*
and (a*a*)
?
Is there a distributive property?
Upvotes: 5
Views: 4003
Reputation: 179402
Kleene star does not distribute. (ab)*
is very different from (a*b*)
.
In your specific example, (aa)*
would match groups of two a
s (thus, it only matches even numbers of a
s), while (a*a*)
is equivalent to (a*)
and matches any sequence of a
s. (In that case, L((aa)*)
is a proper subset of L((a*a*))
, but this is not necessarily true for a general regex).
Upvotes: 6
Reputation: 382132
The (aa)*
group does not match the whole aaa
so yes, there's a difference, it only return you a group of 2 a
.
But (a*a*)
is just the same as (a*)
.
Upvotes: 1
Reputation: 7501
Yes, there is a difference. (aa)* would be groups of aa, whereas (a*a*) would be a's.
Basically, the first phrasing would only be even numbers of a, whereas the second would not in this case.
Upvotes: 0