Which regular expression matches cat and bat, but not at?

2025

Which regular expression matches cat and bat, but not at?

  1. A.

    ^.[cb]at$

  2. B.

    [cat|bat]

  3. C.

    ^at$

  4. D.

    ^[cb]at$

  5. E.

    .*at$

Attempted by 21 students.

Show answer & explanation

Correct answer: D

Correct answer: ^[cb]at$

  • The anchors ^ and $ make the pattern match the complete string.

  • The character class [cb] allows either c or b, followed by at. This gives cat and bat.

  • Because the first character is required, plain at does not match.

Explore the full course: Ibps So It Prelims