ITPEC FE Morning October 2018 Question 5
ITPEC FE Morning October 2018 — Question 5 of 80
Regular Expressions (Pattern Matching) — understanding how regex quantifiers define valid string sets.
The pattern [A-Z]+[0-9]* breaks down as:
- [A-Z]+ — one or more uppercase letters (A–Z)
- [0-9]* — zero or more digits (0–9)
A valid string must consist of only uppercase letters followed optionally by digits, with no other characters allowed.
Checking each option:
- ABCDEF → 6 uppercase letters, 0 digits → matches [A-Z]+[0-9]* ✓
- 456789 → starts with digits, no leading letters → fails [A-Z]+
- ABC+99 → contains literal + character, which is neither [A-Z] nor [0-9]
- ABC99* → contains literal * character, which is neither [A-Z] nor [0-9]
Why not others:
- (a) 456789 has no uppercase letters at the start; [A-Z]+ requires at least one
- (b) ABC+99 includes the character + which is not part of [A-Z] or [0-9]
- (c) ABC99* includes the character * which is not part of [A-Z] or [0-9]
Key rule: + means one or more, * means zero or more — and the regex must match the entire string with no extra characters.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.