Exam-style question
Try this first
Which regular expression recognises strings over a and b that begin with a and end with b, with any number of a or b characters between them?.
- A.a(a|b)*b
- B.b(a|b)*a
- C.(a|b)*ab
- D.a*b*
Answer and explanation
Concise answer
a(a|b)*b
Why this is correct
The initial a requires the string to begin with a, the final b requires it to end with b, and (a|b)* allows zero or more a or b characters in between.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
