MCQs Regular Expression: Python Regular Expression

MCQs Regular Expression. Multiple Choice Questions on the topic of Regular Expression in Python language.


MCQs Regular Expression



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


The expression a{5} will match ________ characters with the previous regular expression ??

a) 5 or less
b) exactly 5
c) 5 or more
d) exactly 4


Which of the following creates a pattern object ??

a) re.create(str)
b) re.regex(str)
c) re.compile(str)
d) re.assemble(str)


The character Dot (that is, ‘.’) in the default mode, matches any character other than ??

a) caret
b) ampersand
c) percentage symbol
d) newline


MCQs Regular Expression


Which module in Python supports regular expressions ??

a) re
b) regex
c) pyregex
d) none of the mentioned


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’)


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’]

b) (‘good’, ‘good’)

c) (‘good’)

d) [‘good’]


Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignored) ??

a) (?:…)
b) (?=…)
c) (?!…)
d) (?#…)


MCQs Regular Expression


What will be the output of the following code ??

re.split(‘mum’, ‘mumbai*’, 1)

a) Error
b) [”, ‘bai*’]
c) [”, ‘bai’]
d) [‘bai*’]


What will be the output of the code ??

re.match(‘sp(.*)am’, ‘spam’)

a) <_sre.SRE_Match object; span=(1, 4), match=’spam’>
b) <_sre.SRE_Match object; span=(0, 4), match=’spam’>
c) No output
d) Error


The difference between the functions re.sub and re.subn is that re.sub returns a _____ whereas re.subn returns a _____ ??

a) string, list
b) list, tuple
c) string, tuple
d) tuple, list


The output of the following two Python codes are the same ??

p = re.compile(‘hello’)
r = p.match(‘hello everyone’)

r = re.match(‘hello’, ‘hello everyone’)

a) True
b) False


MCQs Regular Expression


Choose the option wherein the two choices do not refer to the same option ??

a) re.I

b) re.M

c) re.X

d) re.L


Which of the following special characters matches a pattern only at the end of the string ??

a) \B
b) \X
c) \Z
d) \A


What will be the output ??

re.fullmatch(‘hello’, ‘hello world’)

a) No output
b) []
c) <_sre.SRE_Match object; span=(0, 5), match=’hello’>
d) Error


Read More

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!