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$"));
}
}