What is a regular expression in Python?
A. A sequence of characters that defines a search pattern
B. A built-in function
C. A mathematical expression
D. A special data type
Select an option to see the answer and solution.
What is the purpose of the re.compile() function in Python?
A. It compiles a regular expression pattern into a regular expression object
B. It converts strings to regular expressions
C. It defines a new class
D. It imports the re module
Select an option to see the answer and solution.
Which module in Python supports regular expressions?
A. re
B. regex
C. pyregex
D. none of the mentioned
Select an option to see the answer and solution.
How can you use regular expressions in Python?
A. By using the re module
B. By using the regex keyword
C. By including it as a string
D. By using the regx function
Select an option to see the answer and solution.
What does the match() function in the re module do?
A. It searches for a match only at the beginning of the string
B. It converts strings to regular expressions
C. It searches for a match anywhere in the string
D. It checks if a string contains a specific character
Select an option to see the answer and solution.
What does the findall() function in the re module do?
A. It finds all occurrences of a pattern in a string and returns them as a list
B. It converts strings to regular expressions
C. It searches for a match anywhere in the string
D. It checks if a string contains a specific character
Select an option to see the answer and solution.
What is the purpose of the re.IGNORECASE flag in Python?
A. It makes the pattern matching case-insensitive
B. It compiles a regular expression
C. It specifies a starting position
D. It ignores invalid characters
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)
A. There are number apples and number oranges.
B. An error will occur
C. There are 5 apples and 3 oranges.
D. There are number apples and 3 oranges.
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?
A. By using the search() function from the re module
B. By using the find() function
C. By using the locate() function
D. By using the match() function
Select an option to see the answer and solution.
Which of the following creates a pattern object?
A. re.create(str)
B. re.regex(str)
C. re.compile(str)
D. re.assemble(str)
Select an option to see the answer and solution.
What does the function re.match do?
A. matches a pattern at the start of the string
B. matches a pattern at any position in the string
C. such a function does not exist
D. none of the mentioned
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)
A. ['Hello', 'world']
B. An error will occur
C. ['Hello,', 'world!']
D. ['H', 'w']
Select an option to see the answer and solution.
What does the function re.search do?
A. matches a pattern at the start of the string
B. matches a pattern at any position in the string
C. such a function does not exist
D. none of the mentioned
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())
A. Hello
B. An error will occur
C. world
D. Hello, world!
Select an option to see the answer and solution.
How can you extract a group from a matched regular expression in Python?
A. By using the group() method on the match object
B. By using the extract() function
C. By using the re.extract() method
D. By using the group keyword
Select an option to see the answer and solution.
What is the purpose of the re.DOTALL flag in Python?
A. It makes the . character match any character, including newline
B. It defines a new flag
C. It converts strings to regular expressions
D. It specifies a starting position
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())
A. 5
B. An error will occur
C. 3
D. ['5', '3']
Select an option to see the answer and solution.
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')
Select an option to see the answer and solution.
The function of re.search is . . . . . . . .
A. Matches a pattern at the start of the string
B. Matches a pattern at the end of the string
C. Matches a pattern from any part of a string
D. Such a function does not exist
Select an option to see the answer and solution.
How can you match the beginning of a string using regular expressions?
A. By using the ^ symbol
B. By using the start keyword
C. By using the first keyword
D. By using the initial keyword
Select an option to see the answer and solution.