Loading

Quipoin Menu

Learn • Practice • Grow

python / Regular Expressions
mcq
Direction: Choose the correct option

Q1.

Which module provides regular expression support in Python?
A. re
B. pcre
C. regex
D. regexp
Direction: Choose the correct option

Q2.

What does `re.search(pattern, string)` do?
A. Returns list of all matches
B. Returns a match object if pattern found anywhere in string
C. Searches only at start
D. Splits string
Direction: Choose the correct option

Q3.

How do you find all occurrences of a pattern?
A. Both A and B
B. re.match()
C. re.findall()
D. re.finditer()
Direction: Choose the correct option

Q4.

What is the output of `re.findall(r'd+', 'a1b22c333')`?
A. ['1','22','333']
B. ['1','22','333']
C. ['1','22','333']
D. [1,22,333]
Direction: Choose the correct option

Q5.

What does `re.sub(r's+', '-', 'hello world')` return?
A. 'hello world'
B. 'hello-world'
C. 'hello-world'
D. 'hello-world'
Direction: Choose the correct option

Q6.

How do you compile a regex pattern for reuse?
A. pattern = re.compile(r'...')
B. re.compile(r'...')
C. compile(r'...')
D. re.pattern(r'...')
Direction: Choose the correct option

Q7.

What does `re.match()` do?
A. Checks for a match only at the beginning of the string
B. Checks at end
C. Checks for full string
D. Checks anywhere
Direction: Choose the correct option

Q8.

What is the purpose of groups in regex?
A. To group patterns
B. All of the above
C. To create sub-patterns
D. To capture parts of the match
Direction: Choose the correct option

Q9.

How do you access captured groups in a match object?
A. All of the above
B. match[1]
C. match.group(1)
D. match.groups()[0]
Direction: Choose the correct option

Q10.

What does the flag `re.IGNORECASE` do?
A. Matches newlines
B. Ignores whitespace
C. Ignores comments
D. Makes matching case-insensitive