Freshers Registration

Java Regex Quiz – Java Regex Multiple Choice Questions and Answers

Java Regex Quiz

Java Regex Quiz – Java Regex Multiple Choice Questions and Answers: Want to challenge your expertise in Java Regular Expression? If you are yes for it, take up the Java Regex Quiz from here. Thus, by the end, you will get to know how much you are aware of with Core Java Regular Expression concepts. Java Regular Expression Questions & Answers articulated here are the most common questions that are been asked in the interviews. Don’t miss this chance to attempt the Java Regular Expressions Quiz as in submission you will get the Java Regex Multiple Choice Questions and Answers as a response. After taking part in the Java Regex Online Quiz Test, check that in what areas you were needed to have improvement.

Java Regex Quiz – Overview

Quiz Name Java Regex
Exam Type MCQ (Multiple Choice Questions)
Category Technical Quiz
Mode of Quiz Online

Java Regex Online Quiz Test – Test your Expertise

What does the regular expression “\d” match in Java?
a. Any letter
b. Any digit
c. Any whitespace character
d. Any non-digit character
Answer: b. Any digit
Explanation: The regular expression “\d” matches any digit character in Java.

Join Telegram Join Telegram
Join Whatsapp Groups Join Whatsapp

Which of the following regular expressions matches any sequence of characters?
a. “\w+”
b. “\d+”
c. “.+”
d. “\s+”
Answer: c. “.+”
Explanation: The regular expression “.+” matches any sequence of characters, including whitespace and special characters.

What is the purpose of the regular expression “^\w{5,10}$” in Java?
a. Matches any word with 5-10 characters
b. Matches any word starting with a letter
c. Matches any word ending with a number
d. Matches any word with at least one uppercase letter
Answer: a. Matches any word with 5-10 characters
Explanation: The regular expression “^\w{5,10}$” matches any word with 5-10 characters, including letters, digits, and underscores.

Which of the following regular expressions matches any whitespace character in Java?
a. “\s”
b. “\S”
c. “\w”
d. “\W”
Answer: a. “\s”
Explanation: The regular expression “\s” matches any whitespace character, including space, tab, and newline characters.

What is the purpose of the regular expression “(cat|dog)” in Java?
a. Matches any word that contains “cat” or “dog”
b. Matches any word that starts with “cat” or “dog”
c. Matches any word that ends with “cat” or “dog”
d. Matches any word that is either “cat” or “dog”
Answer: d. Matches any word that is either “cat” or “dog”
Explanation: The regular expression “(cat|dog)” matches any word that is either “cat” or “dog”.

Which of the following regular expressions matches any lowercase letter in Java?
a. “\d”
b. “\w”
c. “[a-z]”
d. “\S”
Answer: c. “[a-z]”
Explanation: The regular expression “[a-z]” matches any lowercase letter.

What is the purpose of the regular expression “\b” in Java?
a. Matches the beginning of a string
b. Matches the end of a string
c. Matches a word boundary
d. Matches any whitespace character
Answer: c. Matches a word boundary
Explanation: The regular expression “\b” matches a word boundary, which is the position between a word character and a non-word character.

Which of the following regular expressions matches any non-digit character in Java?
a. “\d”
b. “\D”
c. “\s”
d. “\S”
Answer: b. “\D”
Explanation: The regular expression “\D” matches any non-digit character.

What is the purpose of the regular expression “(?=.\d)(?=.[a-z])(?=.[A-Z]).{8,}” in Java?
a. Matches any password that contains at least one digit, one lowercase letter, one uppercase letter, and is at least 8 characters long
b. Matches any email address
c. Matches any phone number
d. Matches any IP address
Answer: a. Matches any password that contains at least one digit, one lowercase letter, one uppercase letter, and is at least 8 characters long
Explanation: The regular expression “(?=.\d)(?=.[a-z])(?=.[A-Z]).{8,}” matches any password that contains at least one digit, one lowercase letter, one uppercase letter, and is at least 8 characters long. The expression uses positive lookahead assertions to ensure that the password contains at least one digit, one lowercase letter, and one uppercase letter, and the “.{8,}” portion matches any string that is at least 8 characters long.

Which of the following regular expressions matches any email address in Java?
a. “\w+@\w+.\w+”
b. “\d+@\w+.\w+”
c. “\S+@\S+.\S+”
d. “\w+@\S+.\w+”
Answer: d. “\w+@\S+.\w+”
Explanation: The regular expression “\w+@\S+.\w+” matches any email address that contains one or more word characters before the “@” symbol, followed by one or more non-whitespace characters, a dot, and one or more word characters.

What is the purpose of the regular expression “(?<=Mr|Mrs|Ms).?\s[A-Z]\w*” in Java?
a. Matches any string that contains “Mr”, “Mrs”, or “Ms”, followed by an optional period and a space, and then an uppercase word
b. Matches any string that starts with “Mr”, “Mrs”, or “Ms”
c. Matches any string that ends with an uppercase word
d. Matches any string that contains an uppercase word after “Mr”, “Mrs”, or “Ms”
Answer: a. Matches any string that contains “Mr”, “Mrs”, or “Ms”, followed by an optional period and a space, and then an uppercase word
Explanation: The regular expression “(?<=Mr|Mrs|Ms).?\s[A-Z]\w*” matches any string that contains “Mr”, “Mrs”, or “Ms”, followed by an optional period and a space, and then an uppercase word.

Which of the following regular expressions matches any string that starts with a digit in Java?
a. “^\d”
b. “\d$”
c. “\D+”
d. “\d+”
Answer: a. “^\d”
Explanation: The regular expression “^\d” matches any string that starts with a digit.

What is the purpose of the regular expression “[^aeiou]” in Java?
a. Matches any string that contains all lowercase vowels
b. Matches any string that contains at least one lowercase vowel
c. Matches any string that does not contain any lowercase vowels
d. Matches any string that contains only lowercase vowels
Answer: c. Matches any string that does not contain any lowercase vowels
Explanation: The regular expression “[^aeiou]” matches any character that is not a lowercase vowel.

Which of the following regular expressions matches any string that ends with a digit in Java?
a. “\d$”
b. “^\d”
c. “\D+”
d. “\d+”
Answer: a. “\d$”
Explanation: The regular expression “\d$” matches any string that ends with a digit.

What is the purpose of the regular expression “(?i)hello” in Java?
a. Matches any string that contains the word “hello” in lowercase or uppercase letters
b. Matches any string that contains the word “hello” in uppercase letters only
c. Matches any string that starts with the word “hello”
d. Matches any string that ends with the word “hello”
Answer: a. Matches any string that contains the word “hello” in lowercase or uppercase letters
Explanation: The regular expression “(?i)hello” matches any string that contains the word “hello” in lowercase or uppercase letters. The “(?i)” portion specifies that the match should be case-insensitive.

Which of the following regular expressions matches any string that contains a sequence of two or more consecutive vowels in Java?
a. “[aeiou]{2}”
b. “[aeiou]+”
c. “[^aeiou]”
d. “[aeiou]{2,}”
Answer: d. “[aeiou]{2,}”
Explanation: The regular expression “[aeiou]{2,}” matches any string that contains two or more consecutive vowels.

What is the purpose of the regular expression “\b\w{5}\b” in Java?
a. Matches any string that contains a word that is exactly 5 letters long
b. Matches any string that contains a word that starts with the letter “b” and is exactly 5 letters long
c. Matches any string that contains a word that ends with the letter “b” and is exactly 5 letters long
d. Matches any string that contains a word that has a length of at least 5 letters
Answer: a. Matches any string that contains a word that is exactly 5 letters long
Explanation: The regular expression “\b\w{5}\b” matches any word that is exactly 5 letters long. The “\b” portions specify word boundaries, and the “\w{5}” portion matches any word character that appears exactly 5 times.

Which of the following regular expressions matches any string that contains a backslash () character in Java?
a. “\”
b. “\”
c. “\\\”
d. “\\\\”
Answer: d. “\\\\”
Explanation: The regular expression “\\\\” matches any string that contains a backslash character. In Java regular expressions, a backslash needs to be escaped by another backslash, so the regular expression contains 4 backslashes.

What is the purpose of the regular expression “(?<=\d)(?=(\d\d\d)+\b)” in Java?
a. Matches any string that contains three consecutive digits
b. Matches any string that contains a number with at least three digits
c. Matches any string that contains a number with exactly three digits
d. Matches any string that contains a number with at most three digits
Answer: b. Matches any string that contains a number with at least three digits
Explanation: The regular expression “(?<=\d)(?=(\d\d\d)+\b)” matches any string that contains a number with at least three digits. The “(?<=\d)” portion specifies a positive lookbehind assertion for a digit, and the “(?=(\d\d\d)+\b)” portion specifies a positive lookahead assertion for one or more groups of three digits followed by a word boundary.

Which of the following regular expressions matches any string that contains a valid IPv4 address in Java?
a. “\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}”
b. “\d{1,3}.\d{1,3}.\d{1,3}.\d{1,4}”
c. “\d{1,4}.\d{1,4}.\d{1,4}.\d{1,4}”
d. “\d{1,4}.\d{1,4}.\d{1,4}.\d{1,3}”
Answer: a. “\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}”
Explanation: The regular expression “\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}” matches any string that contains a valid IPv4 address

So much glad that you have utilized this portal to measure your knowledge in core Java through Java Regex Online Quiz Test. If you are willing to take more quiz tests relates to core concepts of Java, then make use of our Technical Quizzes page which you will find in our freshersnow.com portal.

Freshersnow.com is one of the best job sites in India. On this website you can find list of jobs such as IT jobs, government jobs, bank jobs, railway jobs, work from home jobs, part time jobs, online jobs, pharmacist jobs, software jobs etc. Along with employment updates, we also provide online classes for various courses through our android app. Freshersnow.com also offers recruitment board to employers to post their job advertisements for free.