ITPEC IP October 2023 Question 2
A search is performed by specifying a character string comprised of multiple alphabetic characters and one delimiter character “.” (period). An “*” (asterisk) represents an arbitrary character string with zero or more characters, and a “?” (question mark) represents an arbitrary single character. Which of the following is a character string that matches the character string represented below?
X*.Y??
Explanation
XYX.YXY — the pattern needs an X at the start, a period, then a Y followed by exactly two more characters.
Read X*.Y?? piece by piece:
- •
X*— the name before the period starts with X; the asterisk then allows any string, even an empty one - •
.— the one period - •
Y??— after the period, a Y and exactly two single characters, so exactly three characters in all
XYX.YXY fits: XYX starts with X, and YXY is a Y plus two characters.
Answer (c)
Why not others:
- •(a) XY.XYY — the part after the period starts with X, not Y
- •(b) XXX.YY — only two characters follow the period;
Y??needs three - •(d) YXYX.YXY — the part before the period starts with Y, not X;
X*fixes the first character
Key rule: An asterisk matches any number of characters, including none, while each question mark matches exactly one, so ?? fixes the length of that part.
Software · 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 IP past-paper collection or Report an issue.