phpkleene-star

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


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.


Solution

  • (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.