質問

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 ?

役に立ちましたか?

解決

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

他のヒント

The only way your description is accurate is if you interpret the expression a+b as a or b. Most regular expression tools write this using a vertical bar, as in a|b. The other commenters and answerers have interpreted the + as a postfix operator meaning "one or more".

Using that reading, the reason every string in this set must be of even length is because the repetition comes outside a string of length 2. It means "zero or more copies of either aa or ba". Clearly every word matching that description is of even length. 0 is even by definition, and every second letter has to be an a.

{ ¢, aa, ba, aaaa, aaba, baaa, baba, ... }

OP, your question is based on curriculum from lecture and text where + is intended as an OR operation. The text and lecture material makes very clear what the notation means...

(b(bb)*)* = 0-n b's followed by 0-n bb's. in other words, zero or more b's.

(a(aa)*b(bb)*)* follows the pattern 2n + 1 a's following with 2n + 1 b's, if not an empty string.

((a+b)a)* is more ambiguous i.e. more things could be said about it than the answer, but the answer cannot be said to be wrong either. It is all words of even length composed of all a's, or a's and b's. My guess is that this answer would have gotten partial credit, and full credit for including the part about a's being the even letter.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top