Skip to main content

Regular Expressions In Python — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Regular Expressions In Python — Part 1 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

What is a regular expression in Python?

Question 2 of 40
★ FPSC ★ PPSC

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

Question 3 of 40
★ FPSC ★ PPSC

Which module in Python supports regular expressions?

Question 4 of 40
★ FPSC ★ PPSC

How can you use regular expressions in Python?

Question 5 of 40
★ FPSC ★ PPSC

What does the match() function in the re module do?

Question 6 of 40
★ FPSC ★ PPSC

What does the findall() function in the re module do?

Question 7 of 40
★ FPSC ★ PPSC

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

Question 8 of 40
★ FPSC ★ PPSC

What is the output of the following code: import re result = re.sub(r'd+', 'number', 'There are 5 apples and 3 oranges.') print(result)

Question 9 of 40
★ FPSC ★ PPSC

How can you search for a specific pattern in a string using regular expressions in Python?

Question 10 of 40
★ FPSC ★ PPSC

Which of the following creates a pattern object?

Question 11 of 40
★ FPSC ★ PPSC

What does the function re.match do?

Question 12 of 40
★ FPSC ★ PPSC

What is the output of the following code: import re result = re.findall(r'bw+b', 'Hello, world!') print(result)

Question 13 of 40
★ FPSC ★ PPSC

What does the function re.search do?

Question 14 of 40
★ FPSC ★ PPSC

What is the output of the following code: import re result = re.search(r'hello', 'Hello, world!', re.IGNORECASE) print(result.group())

Question 15 of 40
★ FPSC ★ PPSC

How can you extract a group from a matched regular expression in Python?

Question 16 of 40
★ FPSC ★ PPSC

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

Question 17 of 40
★ FPSC ★ PPSC

What will be the output of the following code: import re pattern = re.compile(r'd+') result = pattern.search('There are 5 apples and 3 oranges.') print(result.group())

Question 18 of 40
★ FPSC ★ PPSC

Which of the codes shown below results in a match?

Question 19 of 40
★ FPSC ★ PPSC

The function of re.search is . . . . . . . .

Question 20 of 40
★ FPSC ★ PPSC

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

Question 21 of 40
★ FPSC ★ PPSC

The function re.error raises an exception if a particular string contains no match for the given pattern.

Question 22 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.split('\W+', 'Hello, hello, hello.')

Question 23 of 40
★ FPSC ★ PPSC

. . . . . . . . matches the start of the string. . . . . . . . . matches the end of the string.

Question 24 of 40
★ FPSC ★ PPSC

What is the output of the following code: import re result = re.search(r'd{2}', 'There are 25 apples and 3 oranges.') print(result.group())

Question 25 of 40
★ FPSC ★ PPSC

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

Question 26 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.subn('A', 'X', 'AAAAAA', count=4)

Question 27 of 40
★ FPSC ★ PPSC

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

Question 28 of 40
★ FPSC ★ PPSC

Which of the following functions clears the regular expression cache?

Question 29 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.split(r'\s+', 'Chrome is better than explorer', maxspilt=3)

Question 30 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? import re re.ASCII

Question 31 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.escape('new**world')

Question 32 of 40
★ FPSC ★ PPSC

Which of the following functions results in case insensitive matching?

Question 33 of 40
★ FPSC ★ PPSC

Which of the following will result in an error?

Question 34 of 40
★ FPSC ★ PPSC

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

Question 35 of 40
★ FPSC ★ PPSC

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

Question 36 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? m = re.search('a', 'The blue umbrella') m.re.pattern

Question 37 of 40
★ FPSC ★ PPSC

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.groupdict())

Question 38 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? re.match('sp(.*)am', 'spam')

Question 39 of 40
★ FPSC ★ PPSC

How can you specify a range of characters in a character class in regular expressions?

Question 40 of 40
★ FPSC ★ PPSC

What will be the output of the following Python function? re.findall("hello world", "hello", 1)

✓ 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 →