• +91 9723535972
  • info@interviewmaterial.com

Regular Expressions Interview Questions and Answers

Question - Create a regular expression that accepts alphanumeric characters only. Its length must be five characters long only

Answer -

import java.util.regex.*;

public class RegexTutorial {
public static void main(String args[]) {
System.out.println(Pattern.matches("[a-zA-Z0-9]{5}", "java1"));
System.out.println(Pattern.matches("[a-zA-Z0-9]{5}", "java12"));
System.out.println(Pattern.matches("[a-zA-Z0-9]{5}", "JA1Va"));
System.out.println(Pattern.matches("[a-zA-Z0-9]{5}", "Java$"));
}
}  

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners