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