Regular expression: does Kleene star have a distributive property?
Asked Answered
W

3

5

Would there be a difference between (aa)* and (a*a*)?

Is there a distributive property?

Writing answered 7/3, 2013 at 7:13 Comment(0)
S
6

Kleene star does not distribute. (ab)* is very different from (a*b*).

In your specific example, (aa)* would match groups of two as (thus, it only matches even numbers of as), while (a*a*) is equivalent to (a*) and matches any sequence of as. (In that case, L((aa)*) is a proper subset of L((a*a*)), but this is not necessarily true for a general regex).

Salesroom answered 7/3, 2013 at 7:15 Comment(0)
D
1

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

Dianoia answered 7/3, 2013 at 7:16 Comment(0)
A
0

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.

Antiscorbutic answered 7/3, 2013 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.