Skip to main content

Regular Expressions In Java — Part 1 MCQs with Explanations

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

Question 2 of 40
★ FPSC ★ PPSC

Which class is used to compile a regular expression in Java?

Question 3 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `.` represent?

Question 4 of 40
★ FPSC ★ PPSC

What does the character class `[A-Za-z]` match in a regular expression?

Question 5 of 40
★ FPSC ★ PPSC

Which quantifier is used in a regular expression to match one or more occurrences of the preceding character or group?

Question 6 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `^` represent when used at the beginning of a pattern?

Question 7 of 40
★ FPSC ★ PPSC

Which class is used to perform matching operations with regular expressions in Java?

Question 8 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `$` represent when used at the end of a pattern?

Question 9 of 40
★ FPSC ★ PPSC

What does the character class `[0-9]` match in a regular expression?

Question 10 of 40
★ FPSC ★ PPSC

Which method is used to find the next subsequence that matches the pattern in a regular expression in Java?

Question 11 of 40
★ FPSC ★ PPSC

Which class is used to represent a compiled regular expression in Java?

Question 12 of 40
★ FPSC ★ PPSC

What is the purpose of the `matches()` method in Java regular expressions?

Question 13 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `d` represent?

Question 14 of 40
★ FPSC ★ PPSC

Which method is used to replace text that matches a regular expression in Java?

Question 15 of 40
★ FPSC ★ PPSC

What does the character class `[A-Z]` match in a regular expression?

Question 16 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `s` represent?

Question 17 of 40
★ FPSC ★ PPSC

Which method is used to split a string using a regular expression in Java?

Question 18 of 40
★ FPSC ★ PPSC

What is the purpose of the `group()` method in Java regular expressions?

Question 19 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `w` represent?

Question 20 of 40
★ FPSC ★ PPSC

Which method is used to append replacement text in a Java regular expression operation?

Question 21 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `b` represent?

Question 22 of 40
★ FPSC ★ PPSC

What is the purpose of the `quote()` method in Java regular expressions?

Question 23 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `Q` represent?

Question 24 of 40
★ FPSC ★ PPSC

Which class is used to represent a group of characters in a regular expression in Java?

Question 25 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `A` represent?

Question 26 of 40
★ FPSC ★ PPSC

What is the purpose of the `reset()` method in Java regular expressions?

Question 27 of 40
★ FPSC ★ PPSC

In a regular expression, what does the metacharacter `G` represent?

Question 28 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? import java.text.*; import java.util.*; class Date_formatting { public static void main(String args[]) { Date date = new Date(); SimpleDateFormat sdf; sdf = new SimpleDateFormat("hh:mm:ss"); System.out.print(sdf.format(date)); } } Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).

Question 29 of 40
★ FPSC ★ PPSC

What does public int end(int group) return?

Question 30 of 40
★ FPSC ★ PPSC

What is the significance of Matcher class for regular expression in java?

Question 31 of 40
★ FPSC ★ PPSC

Which capturing group can represent the entire expression?

Question 32 of 40
★ FPSC ★ PPSC

Which of the following matches end of the string using regular expression in java?

Question 33 of 40
★ FPSC ★ PPSC

Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time?

Question 34 of 40
★ FPSC ★ PPSC

Which of the following is not a class of java.util.regex?

Question 35 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? import java.text.*; import java.util.*; class Date_formatting { public static void main(String args[]) { Date date = new Date(); SimpleDateFormat sdf; sdf = new SimpleDateFormat("E MMM dd yyyy"); System.out.print(sdf.format(date)); } } Note: The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).

Question 36 of 40
★ FPSC ★ PPSC

What does public int start() return?

Question 37 of 40
★ FPSC ★ PPSC

groupCount reports a total number of Capturing groups.

Question 38 of 40
★ FPSC ★ PPSC

Which of these package is used for text formatting in Java programming language?

Question 39 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? import java.text.*; import java.util.*; class Date_formatting { public static void main(String args[]) { Date date = new Date(); SimpleDateFormat sdf; sdf = new SimpleDateFormat("mm:hh:ss"); System.out.print(sdf.format(date)); } } Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).

Question 40 of 40
★ FPSC ★ PPSC

Which of this class can be used to format dates and times?

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