1.

Which of the following lines of code will not show a match?(a) >>> re.match(‘ab*’, ‘a’)(b) >>> re.match(‘ab*’, ‘ab’)(c) >>> re.match(‘ab*’, ‘abb’)(d) >>> re.match(‘ab*’, ‘ba’)This question was addressed to me in an international level competition.I would like to ask this question from Regular Expressions topic in section Regular Expressions and Files of Python

Answer»

The correct CHOICE is (d) >>> re.match(‘ab*’, ‘BA’)

Explanation: In the code shown above, ab* will match to ‘a’ or ‘ab’ or ‘a’ followed by any NUMBER of B’s. HENCE the only line of code from the above options which does not result in a match is:

>>> re.match(‘ab*’, ‘ba’).



Discussion

No Comment Found

Related InterviewSolutions