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

1/5

Page

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

What is a regular expression in Python?

Select an option to see the answer and solution.

What is the purpose of the re.compile() function in Python?

Select an option to see the answer and solution.

Which module in Python supports regular expressions?

Select an option to see the answer and solution.

How can you use regular expressions in Python?

Select an option to see the answer and solution.

What does the match() function in the re module do?

Select an option to see the answer and solution.

What does the findall() function in the re module do?

Select an option to see the answer and solution.

What is the purpose of the re.IGNORECASE flag in Python?

Select an option to see the answer and solution.

What is the output of the following code:
import re
result = re.sub(r'd+', 'number', 'There are 5 apples and 3 oranges.')
print(result)

Select an option to see the answer and solution.

How can you search for a specific pattern in a string using regular expressions in Python?

Select an option to see the answer and solution.

Which of the following creates a pattern object?

Select an option to see the answer and solution.

What does the function re.match do?

Select an option to see the answer and solution.

What is the output of the following code:
import re
result = re.findall(r'bw+b', 'Hello, world!')
print(result)

Select an option to see the answer and solution.

What does the function re.search do?

Select an option to see the answer and solution.

What is the output of the following code:
import re
result = re.search(r'hello', 'Hello, world!', re.IGNORECASE)
print(result.group())

Select an option to see the answer and solution.

How can you extract a group from a matched regular expression in Python?

Select an option to see the answer and solution.

What is the purpose of the re.DOTALL flag in Python?

Select an option to see the answer and solution.

What will be the output of the following code:
import re
pattern = re.compile(r'd+')
result = pattern.search('There are 5 apples and 3 oranges.')
print(result.group())

Select an option to see the answer and solution.

Which of the codes shown below results in a match?

Select an option to see the answer and solution.

The function of re.search is . . . . . . . .

Select an option to see the answer and solution.

How can you match the beginning of a string using regular expressions?

Select an option to see the answer and solution.