Java Programming MCQs - Regular Expressions

This section focuses on the "Regular Expressions" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.

1. Java provides the ______ package for pattern matching with regular expressions.

A. regex
B. java.regex
C. util.regex
D. java.util.regex

View Answer

2. A __________ is a compiled representation of a regular expression.

A. Matcher Object
B. PatternSyntaxException
C. Pattern Object
D. None of the above

View Answer

3. Capturing groups are a way to treat multiple characters as a single unit.

C. Can be true or false
D. Can not say

View Answer

4. Which subexpression matches the beginning of the line.

A. $
B. ^
C. &
D. *

View Answer

5. Subexpression $ is used for?

A. End of the entire string
B. Beginning of the entire string
C. Matches any single character not in brackets
D. Matches the end of the line

View Answer

6. Which of the following matches the nonword characters?

A. w
B. W
C. C
D. c

View Answer

7. Subexpression S is used for?

A. Matches the word characters
B. Matches the whitespace
C. Matches the nonwhitespace
D. Matches the nondigits

View Answer

8. Which method returns the start index of the previous match?

A. public int start(int group)
B. public int end()
C. public int end(int group)
D. public int start()

View Answer

9. What is the use of public boolean find()?

A. Attempts to find the next subsequence of the input sequence that matches the pattern.
B. Attempts to match the input sequence, starting at the beginning of the region, against the pattern.
C. Attempts to match the entire region against the pattern.
D. None of the above

View Answer

10. E Ends quoting begun with Q.

A. Yes
B. No
C. Can be yes or no
D. Can not say

View Answer


* You must be logged in to add comment.