Regex - Interview Questions and Answers for 'Regex' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Regex - Interview Questions and Answers for 'Regex' - 4 question(s) found - Order By Rating

 Q1. Write a regex pattern that would validate if the sting has only alphanumeric characters and no consecutive spaces.Regex
Ans. ^([a-z,A-Z,0-9]*[ ]+)*$

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q2. Write a regex pattern that would validate if the word starts with a alphabet and then alphanumeric thereafter or few special characters (let's say . and _ ).Regex
Ans. ^[a-z,A-Z][a-z,A-Z,0-9,._]*$

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q3. Can you write a regex pattern that would validate if the word starts with a capital alphabet and then alphanumeric thereafter.Regex
Ans. ^[A-Z][a-z,A-Z,0-9]*$

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q4. What's wrong with this code ?

public static void main(String[] args) {
String regex = "(\\w+)*";
String s = "Java is a programming language.";

Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s);
while (matcher.next()) {
System.out.println("The e-mail id is: " + matcher.group());
}
}
Core Java
Ans. matcher.find() should have been used instead of matcher.next() within while.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   regex   pattern.matcher   java.util   coding   code



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: