300-720 · Question #144
The CEO sent an email indicating that all emails containing a string of 123ABCDEFGHJ cannot be delivered and must be sent into quarantine for further inspection. Given the requirement, which regular…
The correct answer is A. \d{3}[A-Z]{9}. The string '123ABCDEFGHJ' consists of exactly 3 numeric digits ('123') followed by exactly 9 uppercase letters ('ABCDEFGHJ'). In regex: '\d' matches any digit (0–9), and '{3}' specifies exactly 3 repetitions; '[A-Z]' matches any uppercase letter, and '{9}' specifies exactly 9…
Question
The CEO sent an email indicating that all emails containing a string of 123ABCDEFGHJ cannot be delivered and must be sent into quarantine for further inspection. Given the requirement, which regular expression should be used to match on that criteria?
Options
- A\d{3}[A-Z]{9}
- B{3}\d{9}[A-Z]
- C\w{3}[A-Z]{9}
- D\D{3}[A-Z]{9}
How the community answered
(13 responses)- A85% (11)
- B8% (1)
- D8% (1)
Explanation
The string '123ABCDEFGHJ' consists of exactly 3 numeric digits ('123') followed by exactly 9 uppercase letters ('ABCDEFGHJ'). In regex: '\d' matches any digit (0–9), and '{3}' specifies exactly 3 repetitions; '[A-Z]' matches any uppercase letter, and '{9}' specifies exactly 9 repetitions. Combined: \d{3}[A-Z]{9}. In the answer choices, double braces {{}} are used due to string formatting escaping, so Choice A (\d{{3}}[A-Z]{{9}}) represents \d{3}[A-Z]{9} - the correct pattern. Choice B inverts the quantifier positions. Choice C uses '\w' which matches word characters (letters, digits, AND underscore), not just digits - too broad for the numeric portion. Choice D uses '\D' which matches non-digit characters, incorrectly matching the numeric prefix.
Topics
Community Discussion
No community discussion yet for this question.