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
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a regular expression in Java?
Correct Answer: Option A — A pattern that describes a set of strings
Detailed Academic Explanation:
A pattern that describes a set of strings is the correct answer to “What is a regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class is used to compile a regular expression in Java?
Correct Answer: Option D — `Pattern`
Detailed Academic Explanation:
`Pattern` is the correct answer to “Which class is used to compile a regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `.` represent?
Correct Answer: Option C — Any character
Detailed Academic Explanation:
Any character is the correct answer to “In a regular expression, what does the metacharacter `.` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the character class `[A-Za-z]` match in a regular expression?
Correct Answer: Option B — Any uppercase or lowercase letter
Detailed Academic Explanation:
Any uppercase or lowercase letter is the correct answer to “What does the character class `[A-Za-z]` match in a regular expression”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which quantifier is used in a regular expression to match one or more occurrences of the preceding character or group?
Correct Answer: Option D — `+`
Detailed Academic Explanation:
`+` is the correct answer to “Which quantifier is used in a regular expression to match one or more occurrences of the preceding character or group”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `^` represent when used at the beginning of a pattern?
Correct Answer: Option A — The start of a line
Detailed Academic Explanation:
The start of a line is the correct answer to “In a regular expression, what does the metacharacter `^` represent when used at the beginning of a pattern”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class is used to perform matching operations with regular expressions in Java?
Correct Answer: Option D — `Matcher`
Detailed Academic Explanation:
`Matcher` is the correct answer to “Which class is used to perform matching operations with regular expressions in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `$` represent when used at the end of a pattern?
Correct Answer: Option C — The end of a line
Detailed Academic Explanation:
The end of a line is the correct answer to “In a regular expression, what does the metacharacter `$` represent when used at the end of a pattern”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the character class `[0-9]` match in a regular expression?
Correct Answer: Option B — Any digit
Detailed Academic Explanation:
Any digit is the correct answer to “What does the character class `[0-9]` match in a regular expression”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to find the next subsequence that matches the pattern in a regular expression in Java?
Correct Answer: Option C — `find()`
Detailed Academic Explanation:
`find()` is the correct answer to “Which method is used to find the next subsequence that matches the pattern in a regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class is used to represent a compiled regular expression in Java?
Correct Answer: Option A — `Pattern`
Detailed Academic Explanation:
`Pattern` is the correct answer to “Which class is used to represent a compiled regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `matches()` method in Java regular expressions?
Correct Answer: Option D — It checks if the entire input sequence matches the pattern
Detailed Academic Explanation:
It checks if the entire input sequence matches the pattern is the correct answer to “What is the purpose of the `matches()` method in Java regular expressions”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `d` represent?
Correct Answer: Option B — Any digit
Detailed Academic Explanation:
Any digit is the correct answer to “In a regular expression, what does the metacharacter `d` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to replace text that matches a regular expression in Java?
Correct Answer: Option C — `replaceAll()`
Detailed Academic Explanation:
`replaceAll()` is the correct answer to “Which method is used to replace text that matches a regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the character class `[A-Z]` match in a regular expression?
Correct Answer: Option D — Any uppercase letter
Detailed Academic Explanation:
Any uppercase letter is the correct answer to “What does the character class `[A-Z]` match in a regular expression”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `s` represent?
Correct Answer: Option A — Any whitespace character
Detailed Academic Explanation:
Any whitespace character is the correct answer to “In a regular expression, what does the metacharacter `s` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to split a string using a regular expression in Java?
Correct Answer: Option D — `split()`
Detailed Academic Explanation:
`split()` is the correct answer to “Which method is used to split a string using a regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `group()` method in Java regular expressions?
Correct Answer: Option C — It returns the matched subsequence
Detailed Academic Explanation:
It returns the matched subsequence is the correct answer to “What is the purpose of the `group()` method in Java regular expressions”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `w` represent?
Correct Answer: Option B — Any word character (letter, digit, or underscore)
Detailed Academic Explanation:
Any word character (letter, digit, or underscore) is the correct answer to “In a regular expression, what does the metacharacter `w` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to append replacement text in a Java regular expression operation?
Correct Answer: Option C — `appendReplacement()`
Detailed Academic Explanation:
`appendReplacement()` is the correct answer to “Which method is used to append replacement text in a Java regular expression operation”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `b` represent?
Correct Answer: Option D — A word boundary
Detailed Academic Explanation:
A word boundary is the correct answer to “In a regular expression, what does the metacharacter `b` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `quote()` method in Java regular expressions?
Correct Answer: Option A — It returns a literal pattern string for the specified string
Detailed Academic Explanation:
It returns a literal pattern string for the specified string is the correct answer to “What is the purpose of the `quote()` method in Java regular expressions”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `Q` represent?
Correct Answer: Option D — The beginning of a quoted section
Detailed Academic Explanation:
The beginning of a quoted section is the correct answer to “In a regular expression, what does the metacharacter `Q` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class is used to represent a group of characters in a regular expression in Java?
Correct Answer: Option C — `CharacterGroup`
Detailed Academic Explanation:
`CharacterGroup` is the correct answer to “Which class is used to represent a group of characters in a regular expression in Java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `A` represent?
Correct Answer: Option B — The beginning of a string
Detailed Academic Explanation:
The beginning of a string is the correct answer to “In a regular expression, what does the metacharacter `A` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `reset()` method in Java regular expressions?
Correct Answer: Option C — It resets the matcher
Detailed Academic Explanation:
It resets the matcher is the correct answer to “What is the purpose of the `reset()` method in Java regular expressions”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a regular expression, what does the metacharacter `G` represent?
Correct Answer: Option D — The end of the previous match
Detailed Academic Explanation:
The end of the previous match is the correct answer to “In a regular expression, what does the metacharacter `G` represent”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 28 of 40
★ FPSC
★ PPSC
★ 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).
Correct Answer: Option D — 03:55:04
Detailed Academic Explanation:
03:55:04 is the correct answer to “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).”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does public int end(int group) return?
Correct Answer: Option A — offset from last character of the subsequent group
Detailed Academic Explanation:
offset from last character of the subsequent group is the correct answer to “What does public int end(int group) return”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the significance of Matcher class for regular expression in java?
Correct Answer: Option C — interpreted both pattern and performs match operations in the string
Detailed Academic Explanation:
interpreted both pattern and performs match operations in the string is the correct answer to “What is the significance of Matcher class for regular expression in java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which capturing group can represent the entire expression?
Correct Answer: Option B — group 0
Detailed Academic Explanation:
group 0 is the correct answer to “Which capturing group can represent the entire expression”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following matches end of the string using regular expression in java?
Correct Answer: Option A — \z
Detailed Academic Explanation:
\z is the correct answer to “Which of the following matches end of the string using regular expression in java”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time?
Correct Answer: Option A — a
Detailed Academic Explanation:
a is the correct answer to “Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a class of java.util.regex?
Correct Answer: Option D — Regex class
Detailed Academic Explanation:
Regex class is the correct answer to “Which of the following is not a class of java.util.regex”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 35 of 40
★ FPSC
★ PPSC
★ 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).
Correct Answer: Option A — Mon Jul 15 2013
Detailed Academic Explanation:
Mon Jul 15 2013 is the correct answer to “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).”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does public int start() return?
Correct Answer: Option C — returns start index of the previous match
Detailed Academic Explanation:
returns start index of the previous match is the correct answer to “What does public int start() return”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
groupCount reports a total number of Capturing groups.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “groupCount reports a total number of Capturing groups.”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these package is used for text formatting in Java programming language?
Correct Answer: Option A — java.text
Detailed Academic Explanation:
java.text is the correct answer to “Which of these package is used for text formatting in Java programming language”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 39 of 40
★ FPSC
★ PPSC
★ 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).
Correct Answer: Option C — 55:03:04
Detailed Academic Explanation:
55:03:04 is the correct answer to “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).”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of this class can be used to format dates and times?
Correct Answer: Option C — DateFormat
Detailed Academic Explanation:
DateFormat is the correct answer to “Which of this class can be used to format dates and times”. This question is standard in competitive examination syllabi for Regular Expressions In Java.
💡Key Conceptual Anchor:Regular Expressions In Java
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡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.