11
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
Answer & Solution
Answer: Option
A
12
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']
Answer & Solution
Answer: Option
B
13
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
Answer & Solution
Answer: Option
B
14
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!
Answer & Solution
Answer: Option
C
15
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
Answer & Solution
Answer: Option
A
16
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
Answer & Solution
Answer: Option
A
17
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']
Answer & Solution
Answer: Option
D
18
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 & Solution
Answer: Option
C
19
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
Answer & Solution
Answer: Option
C
20
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
Answer & Solution
Answer: Option
A