Vidyalelo
Python · all questions

Regular Expressions in Python
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

90

Questions

5/5

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Python code?
re.sub('Y', 'X', 'AAAAAA', count=2)

Select an option to see the answer and solution.

What will be the output of the following Python code?
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.group(2))

Select an option to see the answer and solution.

What will be the output of the following Python code?
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.group(2))

Select an option to see the answer and solution.

Which of the following lines of code will not show a match?

Select an option to see the answer and solution.

The output of the following two Python codes are the same.
CODE 1
>>> re.split(r'(a)(t)', 'The night sky')
CODE 2
>>> re.split(r'\s+', 'The night sky')

Select an option to see the answer and solution.

The character Dot (that is, '.') in the default mode, matches any character other than . . . . . . . .

Select an option to see the answer and solution.

What will be the output of the following Python code?
re.sub('morning', 'evening', 'good morning')

Select an option to see the answer and solution.

What will be the output of the following Python code?
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groups())

Select an option to see the answer and solution.

Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match='aaaa'>.

Select an option to see the answer and solution.

What will be the output of the following Python code?
w = re.compile('[A-Za-z]+')
w.findall('It will rain today')

Select an option to see the answer and solution.