1. Which of the following strings will be matched by the regular expression \"[a
ID: 3733867 • Letter: 1
Question
1. Which of the following strings will be matched by the regular expression "[a-z]*oi[A-Z]?" ? oil coin boing hanoi
2. What is the output of the following segment of code? s = "We are humans" m = re.match(r'(.*) (.*?) (.*)', s) print (m.groups())
A. ('we', 'are', 'humans') B. (we, are, humans) C. ('we', 'humans') D. 'we are humans'
3. 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. Return a list of matches in the string D. Such a function does not exist in Python 4 points
4. The output of the code shown below is: re.split('mum', 'mumbai*') A. Error B. ['', 'bai*'] C. ['', 'bai'] D. ['bai*']
Explanation / Answer
Here are your answers for the questions. Please feel free to post in comments box if you have any queries.
1.In the given expression[a-z]* means, any alphabet can occur any number of times incuding 0 times also i.e any alphabet may be there or may not be there before oi
Again after oi there should be one alphabet only and the word should end.So from the given matches oil and coin matches. hence answer is oil and coin.
3.re.match() checks for a match only at the beginning of the string, while re.search() checks for a match anywhere in the string. so answer is B.
4. re.split() split string by the occurrences of pattern. so here mum is searched and bai* is seperated from mumbai* and it gives[' ','bai*] as output.so B is the answer
2. for this question answer is D because it will match the end and so complete string will come as 'we are humans'.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.