1,370 views
1 votes
1 votes
Which of the following regular expression is equal to names of students starts with ‘R%’ and
ends in ‘_A’ and contain at least 5 characters?
(a) R ∕ % % ∕ _ A (b) R ∕ % _ % ∕ _ A
(c) R ∕ % _ ∕ % _ ∕ _ A (d) R% _ % ∕ _ A

1 Answer

Best answer
3 votes
3 votes
Answer would be option B.

Option A is wrong because the middle % matches 0 or more characters, causing it to select names of length 4 as well.

Notice the escape sequence (default is "\" i.e. backslash) helps us to remove the special meaning attached to "%" and "_"

(Here I assume backslash as escape character)

Option B: "R\%" ensures that R% is present in beginning then '_' ensures that a single character is present and the following "%" ensures that 0 or more characters after that is accepted (leading it to accept the strings of length >5) and at last  "\_A" ensures that "_A" is present in the end of the string.
selected by

No related questions found