Search code examples
regexformal-languages

how to describe this regular expression in English


I am trying to describe regular expression in English here,

and let's say we have for (b(bb)*)*

you would say: zero or more b's

or we can have (a(aa)*b(bb)*)*

you would say: odd number of a's that end in odd number of b's

now my question is about ((a+b)a)*

you would say: words of even length where every even letter is an 'a'

where did the even length come from ??? how did they get every even letter is an 'a' ? is it from the zero a's because zero is an even number ?


Solution

  • ((a+b)a)*
    

    "you would say: words of even length where every even letter is an 'a'"

    This is not a correct description. More accurate would be "words that have at least one a, followed by exactly one b, followed by exactly one a, zero or more times"

    (+ means "one or more", * means "zero or more".)

    It's more about the back and forth of as and bs--there could be million as between the bs, but there's never two bs next to each other.

    And note that the inner parenthesis are not needed. In other words, this is equivalent:

    (a+ba)*
    

    Free spaced:

    (a+     //"a", one or more times
     b      //followed by exactly one "b"
     a      //followed by exactly one "a"
    )*      //zero or more times