-
Java Regular Expression Questions
- 1. Which of the following statements about the regex API are true?
- 2. What is the significance of Matcher class for a regular expression in java?
- 3. An object of which class is used to compile regular expression?
- 4. What is the significance of Matcher class for a regular expression in java?
- 5. What does public int end(int group) return?
- 6. groupCount() reports a total number of Capturing groups.
- 7. Which of the following matches nonword character using regular expression in java?
- 8. Which capturing group can represent the entire expression?
- 9. Which of the following matches the end of the string using regular expression in java?
- 10. Which of the following is not a class of java.util.regex?
- 11. What does public int end(int group) return?
- 12. what does public String replaceAll(string replace) do?
- 13. What does public int start() return?
- 14. Which capturing group can represent the entire expression?
- 15. What is java regex for below string S?
- 16. What is the Regex for below String?
- 17. What is Java Regex for below String?
- 18. Is String.matches() is same as Pattern.matches()?
- 19. Pattern.matches() should only be used when entire input should completely match with Regex.
- 20. Is PatternSyntaxException a checked Exception?
Java Regular Expressions Quiz Regex Questions
We have brought some Java Regular Expressions Quiz Regex Questions to test your Regex Knowledge. If you need to brush up on your Java Regex skill, check out the below tutorials.
Java Regular Expression Questions
1. Which of the following statements about the regex API are true?
A. Instances of the Pattern class are used to match character sequences against a given pattern
B. The package java.util.regex includes an exception called PatternSyntaxException
C. Instances of Matcher class are used to represent regular expressions in the form of String type
D. None of the above
2. What is the significance of Matcher class for a regular expression in java?
A) interprets pattern in the string
B) Performs match in the string
C) interpreted both patterns and performs match operations in the string
D) None of the mentioned.
3. An object of which class is used to compile regular expression?
A) Pattern class
B) Matcher class
C) PatternSyntaxException
D) None of the mentioned
4. What is the significance of Matcher class for a regular expression in java?
A. interprets pattern in the string
B. Performs match in the string
C. interpreted both patterns and performs match operations in the string
D. None of the mentioned
5. What does public int end(int group) return?
A. offset from the last character of the subsequent group
B. offset from the first character of the subsequent group
C. offset from the last character matched
D. offset from the first character matched
6. groupCount() reports a total number of Capturing groups.
A) True
B) False
7. Which of the following matches nonword character using regular expression in java?
A) \w
B) \W
C) \s
D) \S
8. Which capturing group can represent the entire expression?
A) group *
B) group 0
C) group * or group 0
D) None of the mentioned
9. Which of the following matches the end of the string using regular expression in java?
A) \z
B) \\
C) \*
D) \Z
10. Which of the following is not a class of java.util.regex?
A) Pattern class
B) matcher class
C) PatternSyntaxException
D) Regex class
Java Regular Expressions Quiz Continues:
11. What does public int end(int group) return?
A) offset from the last character of the subsequent group
B) offset from the first character of the subsequent group
C) offset from the last character matched
D) offset from the first character matched
12. what does public String replaceAll(string replace) do?
A) Replace all characters that match a pattern with a replacement string
B) Replace the first subsequence that matches a pattern with a replacement string
C) Replace all other than the first subsequence of that matches a pattern with a replacement string
D) Replace every subsequence of the input sequence that matches a pattern with a replacement string
13. What does public int start() return?
A) returns start index of the input string
B) returns start index of the current match
C) returns start index of the previous match
D) None of the above
14. Which capturing group can represent the entire expression?
A. group *
B. group 0
C. group * or group 0
D. None of the mentioned
15. What is java regex for below string S?
S must be of length: 6
First character: 1, 2 or 3
Second character: 1, 2 or 0
Third character: x, s or 0
Fourth character: 3, 0, A or a
Fifth character: x, s or u
Sixth character: . or,
A) ^([1-3][0-2][xs0][30Aa][xsu][.,])$
B) ([1-3][0-2][xs0][30Aa][xsu][.,])
C) ([1-3][0-2][xs0][30Aa][xsu][.,]){6}
D) ^([1-3][0-2][x,s,0][3,0,A,a][x,s,u][\.\,])$
16. What is the Regex for below String?
The string should consist of only lowercase and uppercase letters (no numbers or symbols).
The string should end in s.
A) ^([(?i)a-z]*S)
B) ^((?i)[A-Z]*s)
C) ^([a-zA-Z]*s)$
D) ([a-z]*s)$
17. What is Java Regex for below String?
The string must start with Mr., Mrs., Ms., Dr. or Er.
The rest of the string must contain only one or more English alphabetic letters (upper and lowercase).
A) (Mr,Mrs,Ms,Dr,Er).([a-zA-Z]?)$
B) ^(Mr|Mrs|Ms|Dr|Er)\\.([a-zA-Z]+)$
C) ^(Mr|Mrs|Ms|Dr|Er)\\.([a-zA-Z])$
D) (Mr|Mrs|Ms|Dr|Er)\.([a-zA-Z]+)$
18. Is String.matches() is same as Pattern.matches()?
A) true
B) false
19. Pattern.matches() should only be used when entire input should completely match with Regex.
A) true
B) false
20. Is PatternSyntaxException a checked Exception?
A) true
B) false
We will soon add some more questions to the list of Java Regular Expressions Quiz Regex questions, If you see any error in these questions, please let us know here.
If you are stuck with any of regex, Check it here.
CheckOut our GitHub Page.

![20 Java Regular Expressions Quiz Regex Important Questions [MCQ] 4 Java Regular Expressions Quiz](https://adevguide0926.live-website.com/wp-content/uploads/2019/08/regex-questions.png)