Question 1 of 25
Hints left: 3
Q1
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))
Q2
Which of the following special characters matches a pattern only at the end of the string?
Q3
What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups())
Q4
What will be the output of the following Python code? re.sub('Y', 'X', 'AAAAAA', count=2)
Q5
Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?
Q6
What will be the output of the following Python code? re.sub('morning', 'evening', 'good morning')
Q7
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))
Q8
What will be the output of the following Python code? a = re.compile('0-9') a.findall('3 trees')
Q9
What will be the output of the following Python code? a=re.compile('[0-9]+') a.findall('7 apples and 3 mangoes')
Q10
The function of re.match is . . . . . . . .
Q11
What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group(2))
Q12
The following Python code snippet results in an error. c=re.compile(r'(\d+)(\[A-Z]+)([a-z]+)') c.groupindex
Q13
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())
Q14
The character Dot (that is, '.') in the default mode, matches any character other than . . . . . . . .
Q15
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))
Q16
How can you match the end of a string using regular expressions?
Q17
Which of the following functions creates a Python object?
Q18
Which of the following lines of code will not show a match?
Q19
How can you match either of two patterns in regular expressions using the | operator?
Q20
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)
Q21
What will be the output of the following Python code? s = 'welcome home' m = re.match(r'(.*)(.*?)', s) print(m.group())
Q22
What is the purpose of the re.search() function in Python?
Q23
What will be the output of the following Python code? re.findall('good', 'good is good') re.findall('good', 'bad is good')
Q24
What will be the output of the following Python code? re.fullmatch('hello', 'hello world')
Q25
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')