ITPEC FE Subject A April 2026 Question 4
ITPEC FE Subject A April 2026 — Question 4 of 60
123-456-7890 is the only string that satisfies every part of ^\d{2,4}-\d+-\d{3,4}$.
The pattern demands three groups separated by hyphens:
- •
\d{2,4}— between 2 and 4 digits - •
\d+— one or more digits - •
\d{3,4}— between 3 and 4 digits
123-456-7890 supplies 3, 3 and 4 digits, and the anchors allow nothing else on the line.
Answer (c)
Why not others:
- (a) 123-456-12 — the last group has 2 digits, but \d{3,4} requires at least 3
- (b) 1-234-5678 — the first group has 1 digit, below the minimum of 2
- (d) 12345-678-910 — the first group has 5 digits, above the maximum of 4
Key rule: {m,n} sets both a minimum and a maximum count, while + sets only a minimum of one. The anchors ^ and $ require the whole line to match, so a valid substring is not enough.
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.