What is the output of the following code:import re result = re.sub(r's', '-', 'This is a test.') print(result)
A. This-is-a-test.
B. An error will occur
C. This--is--a--test.
D. This- is a test.
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())A. ('we', 'are', 'humans')
B. (we, are, humans)
C. ('we', 'humans')
D. 'we are humans'
Select an option to see the answer and solution.
Which of the following functions does not accept any argument?
A. re.purge
B. re.compile
C. re.findall
D. re.match
Select an option to see the answer and solution.
How can you match either of two patterns in regular expressions using the | operator?
A. By using `pattern1
B. pattern2`
C. By using pattern1,pattern2
D. By using pattern1/pattern2
Select an option to see the answer and solution.
What is the purpose of the re.search() function in Python?
A. It searches for a match anywhere in the string
B. It converts strings to regular expressions
C. It finds all occurrences of a pattern in a string
D. It checks if a string contains a specific character
Select an option to see the answer and solution.
What will be the output of the following Python code?
re.findall('good', 'good is good')
re.findall('good', 'bad is good')A. [‘good’, ‘good’]
[‘good’]
B. (‘good’, ‘good’)
(good)
C. (‘good’)
(‘good’)
D. [‘good’]
[‘good’]
Select an option to see the answer and solution.
How can you match the end of a string using regular expressions?
A. By using the $ symbol
B. By using the end keyword
C. By using the last keyword
D. By using the terminate keyword
Select an option to see the answer and solution.
What will be the output of the following Python code?
re.fullmatch('hello', 'hello world')A. No output
B. []
C. <_sre.SRE_Match object; span=(0, 5), match='hello'>
D. Error
Select an option to see the answer and solution.
What will be the output of the following Python code?
a=re.compile('[0-9]+')
a.findall('7 apples and 3 mangoes')A. ['apples' 'and' 'mangoes']
B. (7, 4)
C. ['7', '4']
D. Error
Select an option to see the answer and solution.
The function of re.match is . . . . . . . .
A. Error
B. Matches a pattern anywhere in the string
C. Matches a pattern at the end of the string
D. Matches a pattern at the start of the string
Select an option to see the answer and solution.
What will be the output of the following Python code?
import re
s = "A new day"
m = re.match(r'(.*)(.*?)', s)
print(m.group(2))
print(m.group(0))A. No output
A new day
B. No output
No output
C. [‘A’, ‘new’, ‘day’]
(‘A’, ‘new’, ‘day’)
D. Error
[‘A’, ‘new’, ‘day’]
Select an option to see the answer and solution.
What will be the output of the following Python code?
s = 'welcome home'
m = re.match(r'(.*)(.*?)', s)
print(m.group())A. ('welcome', 'home')
B. ['welcome', 'home']
C. welcome home
D. ['welcome' // 'home' ]
Select an option to see the answer and solution.
What is the output of the following code:import re pattern = re.compile(r'(d+)s(w+)') result = pattern.findall('There are 5 apples and 3 oranges.') print(result)
A. [('5', 'apples'), ('3', 'oranges')]
B. An error will occur
C. [('5', 'and'), ('3', 'and')]
D. [('5', '3'), ('apples', 'oranges')]
Select an option to see the answer and solution.
The following Python code snippet results in an error.
c=re.compile(r'(\d+)(\[A-Z]+)([a-z]+)')
c.groupindexSelect an option to see the answer and solution.
What will be the output of the following Python code?
a = re.compile('0-9')
a.findall('3 trees')A. []
B. ['3']
C. Error
D. ['trees']
Select an option to see the answer and solution.
The output of the following two Python codes are the same.
p = re.compile('hello')
r = p.match('hello everyone')
print(r.group(0))
r = re.match('hello', 'hello everyone')
print(r.group(0))Select an option to see the answer and solution.
Which of the following functions creates a Python object?
A. re.compile(str)
B. re.assemble(str)
C. re.regex(str)
D. re.create(str)
Select an option to see the answer and solution.
Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?
A. (?:...)
B. (?=...)
C. (?!...)
D. (?#...)
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.groups())A. ('we', 'are', 'humans')
B. (we, are, humans)
C. ('we', 'humans')
D. 'we are humans'
Select an option to see the answer and solution.
Which of the following special characters matches a pattern only at the end of the string?
Select an option to see the answer and solution.