Which of the following strings would match the regular expression : p+[3 – 5]*[xyz]?
Which of the following strings would match the regular expression : p+[3 – 5]*[xyz]?
I. p443y
II. p6y
III. 3xyz
IV. p35z
V. p353535x
VI. ppp5
Show answerHide answer
Correct answer: (D) I, IV and V only
Explanation
p+[3–5]*[xyz] = one or more p, then any number of 3, 4 or 5, then exactly one of x, y, z. (I) p443y → matched (II) p6y → not matched, since 6 cannot be used (III) 3xyz → not matched, string must start with p (IV) p35z → matched (V) p353535x → matched (VI) ppp5 → not matched, string must end with x, y or z