Search code examples
context-free-grammarregular-languageautomatalanguage-theory

Does aabbabb belong to the regular expression ((a*| b*)bb)*?


I'm just curious if ((a*| b*)bb)* means that whatever number of a's or b's used in the inner parentheses must be fixed. Like if I had aabb, I could not follow it with a different number of a's? `

Would something like abbaabb or a bbbabb or bbbaaabb etc belong to the regular expression?


Solution

  • Regular expressions are implemented with state machines. It means that they don’t have any memory of what was matched before and they only know about the current state, no matter how you arrived there.

    Regular expressions don’t care if you arrived to the state with “a”, “aaa”, “bb”, “”, or any other match in (a*|b*). Therefore, the answer is that the matching of the inner group is not fixed.