Which of the codes shown below results in a match?

Which of the codes shown below results in a match?
A. re.match(‘George(?=Washington)’, ‘George Washington’)
B. re.match(‘George(?=Washington)’, ‘George’)
C. re.match(‘George(?=Washington)’, ‘GeorgeWashington’)
D. re.match(‘George(?=Washington)’, ‘Georgewashington’)
 
Answer: c
Explanation: The code shown above demonstrates the use of the function re.match, along with the special character ?=. This results in a match only when ‘George’ is immediately followed by ‘Washington’. Also, we have not used the module to ignore case. Hence the match is case-sensitive. Therefore the only option which results in a match is:
re.match(‘George(?=Washington)’, ‘GeorgeWashington’)
 

Tìm kiếm

Back
Top