logo

AQA A-Level Computer Science practice

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?

Try the question first, then check the answer and practise the same topic again.

At a glance

MCQ

Type

practice

Style

Topic

Regular languages

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?.

  1. A.a(a|b)*b
  2. B.b(a|b)*a
  3. C.(a|b)*ab
  4. 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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions