101-500 · Question #506
Which wildcards will match the following filenames? (Choose two.) ttyS0 ttyS1 ttyS2
The correct answer is B. tty?[0-5] D. tty[A-Z][012]. You've hit your Sonnet limit · resets Jun 8, 9am (UTC)
Question
Options
- AttyS[1-5]
- Btty?[0-5]
- Ctty*2
- Dtty[A-Z][012]
- Etty[Ss][02]
How the community answered
(58 responses)- A3% (2)
- B81% (47)
- C10% (6)
- E5% (3)
Explanation
You've hit your Sonnet limit · resets Jun 8, 9am (UTC)
Topics
Community Discussion
5B and D are your answers here. Option B uses a single wildcard character (the question mark) to match exactly one character, so tty? covers ttyS, and then [0-5] is a character class that covers 0, 1, and 2, meaning it matches all three filenames. Option D uses [A-Z] which is a range class that includes S since it is an uppercase letter, and [012] is a class that explicitly lists the digits 0, 1, and 2, so again all three files match. The others fall short for specific reasons: A misses ttyS0 because [1-5] does not include 0, C only ends in 2 so it cannot match ttyS0 or ttyS1 unless the asterisk expands in an unexpected way, and E includes lowercase s in the class but [02] skips 1 entirely.
Samuel's breakdown is solid, though worth noting the question mark in B matches any single character, so tty? would also match files like ttya or tty1 if they existed, meaning it works here only because the filesystem has exactly those three files and nothing else unexpected starting with tty.
E looks right but [02] skips ttyS1, so B and D.
Almost went A, but ttyS0 drops out since 0 is outside 1-5, B and D nail all three.
The hook I use is "B and D, Big Deal" because the question mark in B grabs any single character sitting in that S slot and [0-5] covers all three digits, while D uses [A-Z] which locks onto uppercase S perfectly with [012] finishing the job. On my actual exam I almost circled E thinking tty[Ss][02] was slick, then I caught it dead in its tracks because [02] skips the number 1 entirely, ttyS1 gets left out in the cold, and I literally whispered "gotcha" to my monitor and moved on.