Kleene star in programming. Difference between (a|b)* and a*b*?

555 views Asked by At

What is the difference between (a|b)* and a*b*? Can you show more examples of Kleene star and patterns? I've searched so many sites in Google, but it returns very little results on this topic. I would be very grateful as I am trying to understand how PHP regular expressions work.

1

There are 1 answers

0
Chris Nash On BEST ANSWER

(a|b)* means "a or b, any number of times". a*b* means "Any number of a's then followed by any number of b's". So there exist strings ("baa", "abba", etc) that match the first, but not the second.