ITPEC FE Subject A April 2026 Question 4
In regular expressions (regex), which of the following is the string that correctly matches the pattern ^\d{2, ? Here, “\d” represents a decimal digit 0-9, the “+” symbol indicates one or more repetitions, and the “$” symbol denotes the line's end.
Explanation
123-456-7890 — the only string whose three digit groups fall within every count range the pattern sets.
The anchors ^ and $ make the whole line match \d{2,:
- •
\d{2,— 2 to 4 digits4} - •
\d+— one or more digits - •
\d{3,— 3 or 4 digits4}
123-456-7890 has groups of 3, 3 and 4 digits, all within range.
Answer (c)
Why not others:
- •(a) 123-456-12 — the last group has 2 digits, below the minimum of 3 in
\d{3,4} - •(b) 1-234-5678 — the first group has 1 digit, below the minimum of 2 in
\d{2,4} - •(d) 12345-678-910 — the first group has 5 digits, above the maximum of 4; the ^ anchor stops the match from starting at the second digit
Key rule: {m, sets both a minimum and a maximum count while + sets only a minimum of one, and the ^ and $ anchors require the whole line to match, not just a substring.
Basic Theory · AI-written, may contain errors
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.