Java Regex(Engineering > Computer Science And Engineering ) Questions and Answers

Question 1. What is the significance of Matcher class for regular expression in java?
  1.    interpretes pattern in the string
  2.    Performs match in the string
  3.    interpretest both pattern and performs match operations in the string
  4.    None of the mentioned
Explanation:-
Answer: Option C. -> interpretest both pattern and performs match operations in the string





Question 2. Which of the following identity is wrong?
  1.    R + R = R
  2.    (R*)* = R*
  3.    Both A and B
  4.    (phi)R = R(phi) = RR*
Explanation:-
Answer: Option D. -> (phi)R = R(phi) = RR*





Question 3. Which capturing group can represent the entire expression?
  1.    group *
  2.    group 0
  3.    group * or group 0
  4.    None of the mentioned
Explanation:-
Answer: Option B. -> group 0





Question 4. What does public int end(int group) return?
  1.    offset from last character of the subsequent group
  2.    offset from first character of the subsequent group
  3.    offset from last character matched
  4.    offset from first character matched
Explanation:-
Answer: Option A. -> offset from last character of the subsequent group





Question 5. Which of the following is not a class of java.util.regex?
  1.    Pattern class
  2.    matcher class
  3.    PatternSyntaxException
  4.    Regex class
Explanation:-
Answer: Option D. -> Regex class





Question 6. The set of all strings over Sigma = {a,b} in which all strings having bbbb as substring is
  1.    (a+b)* bbbb (a+b)*
  2.    (a+b)* bb (a+b)*bb
  3.    bbbb (a+b)*
  4.    bb (a+b)*
Explanation:-
Answer: Option A. -> (a+b)* bbbb (a+b)*





Question 7. Regular expressions are used to represent which language
  1.    Recursive language
  2.    Context free language
  3.    Regular language
  4.    All of these
Explanation:-
Answer: Option C. -> Regular language





Question 8. What are the main methods of Java Regex?
  1.    matches
  2.    lookingAt
  3.    find
  4.    All of the above
Explanation:-
Answer: Option D. -> All of the above





Question 9. What does public int start() return?
  1.    returns start index of the input string
  2.    returns start index of the current match
  3.    returns start index of the previous match
  4.    none of the mentioned
Explanation:-
Answer: Option C. -> returns start index of the previous match





Question 10. Which of the following statements about the regex API are true?
  1.    Instances of the Pattern class are used to match character sequences against a given pattern
  2.    The package java.util.regex includes an exception called PatternSyntaxException
  3.    Instances of Matcher class are used to represent regular expressions in the form of String type
  4.    None of the above
Explanation:-
Answer: Option B. -> The package java.util.regex includes an exception called PatternSyntaxException