Skip to main content

Regular Expressions In Python — Part 2 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Regular Expressions In Python — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to . . . . . . . .

Question 2 of 40
★ FPSC ★ PPSC

What is a character class in regular expressions?

Question 3 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.split(r'(a)(t)', 'Maths is a difficult subject')

Question 4 of 40
★ FPSC ★ PPSC

What will be the output of the following code: import re pattern = re.compile(r'b[A-Z]+b') result = pattern.findall('Hello, WORLD!') print(result)

Question 5 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? n = re.sub(r'\w+', 'Hello', 'Cats and dogs')

Question 6 of 40
★ FPSC ★ PPSC

What is the purpose of the re.sub() function in Python?

Question 7 of 40
★ FPSC ★ PPSC

What is the purpose of the re.MULTILINE flag in Python?

Question 8 of 40
★ FPSC ★ PPSC

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

Question 9 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.split('mum', 'mumbai*', 1)

Question 10 of 40
★ FPSC ★ PPSC

The special character B matches the empty string, but only when it is . . . . . . . .

Question 11 of 40
★ FPSC ★ PPSC

Which of the following functions returns a dictionary mapping group names to group numbers?

Question 12 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.split('[a-c]', '0a3B6', re.I)

Question 13 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? import re s = 'abc123 xyz666 lmn-11 def77' re.sub(r'\b([a-z]+)(\d+)', r'\2\1:', s)

Question 14 of 40
★ FPSC ★ PPSC

Which of the following statements regarding the output of the function re.match is incorrect?

Question 15 of 40
★ FPSC ★ PPSC

How can you replace a matched pattern with a new string using regular expressions in Python?

Question 16 of 40
★ FPSC ★ PPSC

Which of the following pattern matching modifiers permits whitespace and comments inside the regular expression?

Question 17 of 40
★ FPSC ★ PPSC

How can you match zero or more occurrences of a pattern in regular expressions?

Question 18 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.split(r'(n\d)=', 'n1=3.1, n2=5, n3=4.565')

Question 19 of 40
★ FPSC ★ PPSC

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

Question 20 of 40
★ FPSC ★ PPSC

What will be the output of the following code: import re result = re.findall(r'd{1,3}', 'There are 25 apples and 300 oranges.') print(result)

Question 21 of 40
★ FPSC ★ PPSC

What is the output of the following code: import re result = re.sub(r's', '-', 'This is a test.') print(result)

Question 22 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group())

Question 23 of 40
★ FPSC ★ PPSC

Which of the following functions does not accept any argument?

Question 24 of 40
★ FPSC ★ PPSC

How can you match either of two patterns in regular expressions using the | operator?

Question 25 of 40
★ FPSC ★ PPSC

What is the purpose of the re.search() function in Python?

Question 26 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.findall('good', 'good is good') re.findall('good', 'bad is good')

Question 27 of 40
★ FPSC ★ PPSC

How can you match the end of a string using regular expressions?

Question 28 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.fullmatch('hello', 'hello world')

Question 29 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? a=re.compile('[0-9]+') a.findall('7 apples and 3 mangoes')

Question 30 of 40
★ FPSC ★ PPSC

The function of re.match is . . . . . . . .

Question 31 of 40
★ FPSC ★ PPSC

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

Question 32 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? s = 'welcome home' m = re.match(r'(.*)(.*?)', s) print(m.group())

Question 33 of 40
★ FPSC ★ PPSC

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)

Question 34 of 40
★ FPSC ★ PPSC

The following Python code snippet results in an error. c=re.compile(r'(\d+)(\[A-Z]+)([a-z]+)') c.groupindex

Question 35 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? a = re.compile('0-9') a.findall('3 trees')

Question 36 of 40
★ FPSC ★ PPSC

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

Question 37 of 40
★ FPSC ★ PPSC

Which of the following functions creates a Python object?

Question 38 of 40
★ FPSC ★ PPSC

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

Question 39 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups())

Question 40 of 40
★ FPSC ★ PPSC

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

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →