I’m still a noob at Regular Expressions, but would anyone be so kind to double check to see if my answer is correct?
Question is: Indicate whether each of the given input strings belong to the language defined by the regex (a | empty) b (a | b)* a (b)*
Empty = flipped around 3 (empty string)
(a) input string: ababaa
Answer: Does not belong to the regex
because if tested, turns out to be ababab
(b) input string: aabbaa
Answer: Does not belong to the regex
Because if tested, turns out to be ab(b or a)* ab
are these answers correct?
The second string does not belong to the language. If you look at the regex, you can see that b must either be the first character (if (a|empty) selects empty), or must be the second character (if (a|empty) selects a). Since the string starts with aa, it can’t match.
The first string does match. Just try to figure out each choice point so that you get the string provided. It might help to work from the outside in, since (a|b)* is the most flexible part of the regex – i.e. you can match whatever you want to it.